Skip to content

Conversation

@dsfaccini
Copy link
Contributor

@dsfaccini dsfaccini commented Nov 17, 2025

Fixes #3428

work in progress:

  • check CI tests and coverage
  • double check code to clarify

tools, strict_tools_requested = self._get_tools(model_request_parameters, model_settings)
tools, mcp_servers, beta_features = self._add_builtin_tools(tools, model_request_parameters)
output_format = self._build_output_format(model_request_parameters)
structured_output_beta_required = strict_tools_requested or bool(output_format)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simplify the code below by adding a value to the beta_headers list here right?

'input_schema': f.parameters_json_schema,
}
if f.strict is not None:
tool_param['strict'] = f.strict # type: ignore[assignment]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at how the OpenAI model uses is_strict_compatible. If the user didn't explicitly say strict=True on their tool, it'll be strict=None, so we check if the schema is strict-compatible, and if so we set strict=True.

So to get the same behavior with Anthropic, we should check if the schema can be transformed successfully (losslessly), and set strict=True unless it's explicitly strict=False

- Resolved conflicts in anthropic.py by keeping our strict tools and native JSON implementation
- Resolved conflicts in test_anthropic.py by merging strict=True with TTL='5m' in assertions
- Kept our test_anthropic_mixed_strict_tool_run test
- Added upstream's new features:
  - count_tokens() method for token counting
  - TTL support for cache control (5m and 1h)
  - New helper methods (_infer_tool_choice, _map_extra_headers)
  - test_anthropic_cache_with_custom_ttl test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Anthropic native JSON output + strict tool calls

2 participants