Output Types
Swarms supports multiple output formats through theoutput_type parameter. output_type controls how the conversation transcript (agent.short_memory) is formatted when agent.run() returns — it is not a schema parser. In particular:
"str"/"string"— the full conversation as one string"str-all-except-first"(default) — the conversation, excluding the first (system prompt) message, joined into one string"final"/"last"— just the content of the last message (a plain string) — this is usually what you want when you also configure alist_base_models/tool_schema, since the model’s final response text is where schema-shaped JSON ends up"json"— the full conversation history serialized as a JSON string (an array of{"role", "content", ...}message dicts, not a single schema-shaped object)"dict"/"dictionary"— the full conversation history as a Pythonlistof message dicts (despite the name, this is a list, not a single dict)"list"— the conversation as a list of message dicts"yaml"— the conversation history as a YAML string"xml"— the conversation history as an XML string"all"— the conversation as a string (same as"string")"dict-all-except-first"— all messages except the first, as a list of message dicts. This is the defaultoutput_typeused internally by several multi-agent harnesses (HeavySwarm,HierarchicalSwarm,SwarmRouter,LLMCouncil,PlannerWorkerSwarm, and others)"list-final"— the content of the last message, wrapped in a single-item list"dict-final"— the content of the last message, as a(content, content)tuple
JSON Schema Output
Basic JSON Schema
Use Pydantic models to define structured output schemas:Multiple Output Schemas
Define multiple possible output formats:Tool Schema
Using tool_schema Parameter
Define output structure usingtool_schema:
Complex Output Structures
Nested Models
Lists and Arrays
Validation and Constraints
Field Validation
Enums and Choices
Output Processing
JSON Output
Dictionary Output
Working with Responses
Pydantic Model Response
Function Calling Response
When tools are used, responses include function calls:Best Practices
1. Use Descriptive Field Names
2. Add Field Descriptions
3. Use Appropriate Constraints
4. Provide Examples in Descriptions
Next Steps
Agent Tools
Add tools to extend agent capabilities
Creating Agents
Learn how to create agents
Reference
- Output type formatting:
swarms/utils/history_output_formatter.py - Pydantic integration:
swarms/tools/pydantic_to_json.py - Tool/list-base-model schema handling:
swarms/structs/agent.py:3059-3087(handle_tool_schema_ops)