Skip to main content
Constrains every LLM call to a JSON schema using WithResponseFormat — the model returns parseable structured data, not free-form markdown. Source: examples/agent_with_json_response/

What it demonstrates

  • interfaces.ResponseFormat with ResponseFormatJSON and JSONSchema
  • Parsing result.Content as JSON after Run
  • Schema enforcement across tool rounds

Run

From examples/:

Key code

Define the schema once at agent construction:
See Response format for provider support and limitations.

Expected output

The model is constrained to return valid JSON matching the schema — result.Content is always parseable with json.Unmarshal.

Learn more

Response Format

Schema design and parsing

Token Usage

Usage on structured runs