JSON Mode & Structured Output
Letta provides two ways to get structured JSON output from agents: Structured Generation through Tools (recommended) and the response_format parameter.
Quick Comparison
Recommended: Use Structured Generation through Tools - works with all providers (Anthropic, OpenAI, Google, etc.) and integrates naturally with Letta’s tool-calling architecture.
Structured Generation through Tools:
- ✅ Universal provider compatibility
- ✅ Both reasoning AND structured output
- ✅ Per-message control
- ✅ Works even as “dummy tool” for pure formatting
response_format parameter:
-
⚠️ OpenAI-compatible providers only (NOT Anthropic)
-
⚠️ Persistent agent state (affects all future responses)
-
✅ Built-in provider schema enforcement
Structured Generation through Tools (Recommended)
Create a tool that defines your desired response format. The tool arguments become your structured data, and you can extract them from the tool call.
Creating a Structured Generation Tool
Using the Structured Generation Tool
The agent will call the tool, and you can extract the structured arguments:
Using response_format for Provider-Native JSON Mode
The response_format parameter enables structured output/JSON mode from LLM providers that support it. This approach is fundamentally different from tools because response_format becomes a persistent part of the agent’s state - once set, all future responses from that agent will follow the format until explicitly changed.
Under the hood, response_format constrains the agent’s assistant messages to follow the specified schema, but it doesn’t affect tools - those continue to work normally with their original schemas.
Requirements for response_format:
- Only works with providers that support structured outputs (like OpenAI) - NOT Anthropic or other providers
Basic JSON Mode
Advanced JSON Schema Mode
For more precise control, you can use OpenAI’s json_schema mode with strict validation:
With structured JSON schema, the agent’s response will be strictly validated:
Updating Agent Response Format
You can update an existing agent’s response format: