Skip to main content

Anthropic

Claude supports structured output via tool use. Pass DOCUMENT_SCHEMA as a tool’s input_schema and force the model to use it with tool_choice.
Claude doesn’t have a native response_format like OpenAI. Instead, we use tool use to enforce the schema. Setting tool_choice to the specific tool name guarantees Claude will output in the correct format.

How it works

  1. SYSTEM_PROMPT tells Claude about the document format
  2. DOCUMENT_SCHEMA is passed as a tool’s input schema
  3. tool_choice forces Claude to call the tool (guaranteeing structured output)
  4. The tool use block’s input contains the document data
  5. Pass it directly to docs.save()