Skip to content

Conversation

@cpsievert
Copy link
Collaborator

Summary

Migrates Anthropic provider to use the new native structured outputs API (output_format parameter) for models that support it.

  • Uses new output_format parameter with beta client for supported models
  • Enables streaming with data_model for Claude 4.5 models (previously not supported)
  • Falls back to tool-based approach for older models
  • Adds model compatibility check (_supports_structured_outputs())

Supported models (new API)

  • claude-sonnet-4-5
  • claude-opus-4-1
  • claude-opus-4-5
  • claude-haiku-4-5

Key benefits

  1. Streaming now works with data_model for supported models
  2. Better validation via Anthropic's constrained decoding
  3. Cleaner response format (JSON in text content instead of fake tool calls)

Documentation

https://platform.claude.com/docs/en/build-with-claude/structured-outputs

Test plan

  • Re-recorded VCR cassettes for data extraction tests
  • Verified streaming with data_model works
  • All 450 tests pass
  • Type checking passes

Note: This PR depends on #262

🤖 Generated with Claude Code

@cpsievert cpsievert changed the base branch from feat/stream-data-model to main January 6, 2026 15:58
@cpsievert cpsievert force-pushed the feat/stream-structured-data branch 5 times, most recently from 1f65317 to 677a184 Compare January 6, 2026 16:31
Use the new output_format parameter and beta client for models that support
structured outputs (claude-sonnet-4-5, claude-opus-4-1, claude-opus-4-5,
claude-haiku-4-5). This enables streaming with data_model for these models.

Older models fall back to the previous tool-based approach.

Documentation: https://platform.claude.com/docs/en/build-with-claude/structured-outputs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@cpsievert cpsievert force-pushed the feat/stream-structured-data branch from 677a184 to b268fe4 Compare January 6, 2026 16:35
cpsievert and others added 3 commits January 6, 2026 11:11
- Rename use_beta_structured_output to _supports_structured_outputs
- Inline STRUCTURED_OUTPUT_MODELS into the function
- Remove streaming fallback/warning for older models (let it fail)
- Make create_data_model_tool a staticmethod
- Revert unnecessary kwargs->api_kwargs rename in _token_count_args
- Remove redundant comments about Beta API type signatures

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Move STRUCTURED_OUTPUTS_BETA and supports_structured_outputs after TYPE_CHECKING
- Make supports_structured_outputs public (remove leading underscore)
- Consolidate data_model handling into single block
- Add TODO for removing legacy tool-based approach

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@cpsievert cpsievert requested a review from Copilot January 6, 2026 17:26

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants