Anthropic
Claude supports structured output via tool use. PassDOCUMENT_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
SYSTEM_PROMPTtells Claude about the document formatDOCUMENT_SCHEMAis passed as a tool’s input schematool_choiceforces Claude to call the tool (guaranteeing structured output)- The tool use block’s
inputcontains the document data - Pass it directly to
docs.save()