@@ -199,8 +199,9 @@ def __init__(
199199 model_name: The name of the Anthropic model to use. List of model names available
200200 [here](https://docs.anthropic.com/en/docs/about-claude/models).
201201 provider: The provider to use for the Anthropic API. Can be either the string 'anthropic' or an
202- instance of `Provider[AsyncAnthropicClient]`. If not provided, the other parameters will be used .
202+ instance of `Provider[AsyncAnthropicClient]`. Defaults to 'anthropic' .
203203 profile: The model profile to use. Defaults to a profile picked by the provider based on the model name.
204+ The default 'anthropic' provider will use the default `..profiles.anthropic_model_profile`.
204205 settings: Default model settings for this model instance.
205206 """
206207 self ._model_name = model_name
@@ -290,13 +291,14 @@ def prepare_request(
290291 and thinking .get ('type' ) == 'enabled'
291292 ):
292293 if model_request_parameters .output_mode == 'auto' :
293- model_request_parameters = replace (model_request_parameters , output_mode = 'prompted' )
294+ output_mode = 'native' if self .profile .supports_json_schema_output else 'prompted'
295+ model_request_parameters = replace (model_request_parameters , output_mode = output_mode )
294296 elif (
295297 model_request_parameters .output_mode == 'tool' and not model_request_parameters .allow_text_output
296298 ): # pragma: no branch
297299 # This would result in `tool_choice=required`, which Anthropic does not support with thinking.
298300 raise UserError (
299- 'Anthropic does not support thinking and output tools at the same time. Use `output_type=PromptedOutput (...)` instead.'
301+ 'Anthropic does not support thinking and output tools at the same time. Use `output_type=NativeOutput (...)` instead.'
300302 )
301303 return super ().prepare_request (model_settings , model_request_parameters )
302304
@@ -330,15 +332,15 @@ async def _messages_create(
330332 # standalone function to make it easier to override
331333 tools , strict_tools_requested = self ._get_tools (model_request_parameters , model_settings )
332334 tools , mcp_servers , beta_features = self ._add_builtin_tools (tools , model_request_parameters )
333- output_format = self ._build_output_format (model_request_parameters )
335+ native_format = self ._native_output_format (model_request_parameters )
334336
335337 tool_choice = self ._infer_tool_choice (tools , model_settings , model_request_parameters )
336338
337339 system_prompt , anthropic_messages = await self ._map_message (messages , model_request_parameters , model_settings )
338340
339341 # Build betas list for SDK
340342 betas : list [str ] = list (beta_features )
341- if strict_tools_requested or output_format :
343+ if strict_tools_requested or native_format :
342344 betas .append ('structured-outputs-2025-11-13' )
343345
344346 try :
@@ -354,7 +356,7 @@ async def _messages_create(
354356 tools = tools or OMIT ,
355357 tool_choice = tool_choice or OMIT ,
356358 mcp_servers = mcp_servers or OMIT ,
357- output_format = output_format or OMIT ,
359+ output_format = native_format or OMIT ,
358360 betas = betas or OMIT ,
359361 stream = stream ,
360362 thinking = model_settings .get ('anthropic_thinking' , OMIT ),
@@ -849,19 +851,18 @@ async def _map_user_prompt(
849851 else :
850852 raise RuntimeError (f'Unsupported content type: { type (item )} ' ) # pragma: no cover
851853
852- @staticmethod
853- def _map_tool_definition (f : ToolDefinition ) -> BetaToolParam :
854+ def _map_tool_definition (self , f : ToolDefinition ) -> BetaToolParam :
854855 tool_param : BetaToolParam = {
855856 'name' : f .name ,
856857 'description' : f .description or '' ,
857858 'input_schema' : f .parameters_json_schema ,
858859 }
859- if f .strict :
860+ if f .strict and self . profile . supports_json_schema_output : # pragma: no branch
860861 tool_param ['strict' ] = f .strict
861862 return tool_param
862863
863864 @staticmethod
864- def _build_output_format (model_request_parameters : ModelRequestParameters ) -> BetaJSONOutputFormatParam | None :
865+ def _native_output_format (model_request_parameters : ModelRequestParameters ) -> BetaJSONOutputFormatParam | None :
865866 if model_request_parameters .output_mode != 'native' :
866867 return None
867868 output_object = model_request_parameters .output_object
0 commit comments