Structured Output

Prompting

Definition

Guaranteed formatted output (typically JSON) from Claude. The most reliable method is to define a schema as a tool and set tool_choice to force its use — Claude's tool_use blocks are always valid JSON. Alternatively, use --output-format json with --json-schema in Claude Code CLI.

Example Usage

Define a JSON schema as a tool definition and set tool_choice: {type: 'tool', name: 'output_schema'} to guarantee parseable output.