Skip to main content
For the full guide, see Structured output.

Basic extraction

Provide an output_schema and the agent will extract validated JSON after the agentic loop completes.
rkat run --output-schema '{
  "type": "object",
  "properties": {
    "city": {"type": "string"},
    "country": {"type": "string"},
    "population": {"type": "integer"}
  },
  "required": ["city", "country", "population"]
}' "Tell me about Tokyo"

Schema from file

The CLI can load a schema from a JSON file instead of inline.
rkat run --output-schema ./schemas/city.json "Tell me about Tokyo"
The CLI detects files by checking if the value is an existing path. The file can contain a raw JSON Schema or the wrapper format with explicit name, strict, compat, and format fields.

Retries

When validation fails, the agent retries the extraction turn with error feedback. The default is 2 retries (3 total attempts).
rkat run --output-schema ./schema.json --structured-output-retries 5 "Extract entities"

Compatibility mode

Schemas are normalized across providers. The compat setting controls how unsupported JSON Schema features are handled during provider-specific lowering.
# Lossy (default): unsupported features are dropped with warnings
rkat run --output-schema ./schema.json --output-schema-compat lossy "Extract data"

# Strict: reject schemas with unsupported features
rkat run --output-schema ./schema.json --output-schema-compat strict "Extract data"
ModeBehavior
lossyBest-effort lowering; unsupported features are dropped with warnings
strictReject schemas with unsupported features for the target provider
Warnings are included in the response as schema_warnings. The same schema works with Anthropic, OpenAI, and Gemini — provider-specific lowering is handled transparently.

Read the result

The structured output appears in the response alongside the raw text.
# --output json returns the full result including structured_output
rkat run --output json --output-schema '{"type":"object","properties":{"answer":{"type":"string"}},"required":["answer"]}' "What is 2+2?"
# stdout: {"session_id":"...","text":"...","structured_output":{"answer":"4"}}