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)
- ⚠️ Requires
send_message
tool to be attached - ✅ 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
overrides the schema for the send_message
tool (which appears as AssistantMessage
in the API), but it doesn’t affect other 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
- The
send_message
tool must be attached to the agent (it’s included by default but can be detached)
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: