docs

Structured Output

Force your agent to return a specific JSON structure. The final response is parsed and validated against your schema, and the agent retries if it does not match.

Define output_type

agentfile.yaml
agents:
  analyzer:
    metadata:
      role: Code analyzer
      goal: Analyze code quality and return structured findings
    runtime:
      provider: anthropic
      model: claude-sonnet-4-6
    output_type:
      type: object
      properties:
        score:
          type: number
          description: Quality score from 0 to 100
        issues:
          type: array
          items:
            type: object
            properties:
              severity:
                type: string
                enum: [low, medium, high, critical]
              description:
                type: string
              file:
                type: string
      required: [score, issues]

How it works

  1. The schema is appended to the system prompt so the agent knows the expected format
  2. After the agent's final response, the runtime extracts JSON (handles markdown fences)
  3. Validates required fields against the schema
  4. If validation fails, the agent is prompted to retry
Works with all providers
Structured output works with all supported providers including Anthropic, OpenAI, Google, DeepSeek, Mistral, Groq, Together AI, OpenRouter, Cerebras, Fireworks, AWS Bedrock, Azure OpenAI, and MiniMax. The schema is provider-agnostic.
On this page