docs(anthropic): nit comments (#34314)

This commit is contained in:
Mason Daugherty
2025-12-12 10:33:23 -05:00
committed by GitHub
parent 75d365418b
commit 13dd115d1d

View File

@@ -2458,15 +2458,16 @@ class ChatAnthropic(BaseChatModel):
formatted_tool: AnthropicTool, formatted_tool: AnthropicTool,
) -> Runnable[LanguageModelInput, BaseMessage]: ) -> Runnable[LanguageModelInput, BaseMessage]:
thinking_admonition = ( thinking_admonition = (
"Anthropic structured output relies on forced tool calling, " "You are attempting to use structured output via forced tool calling, "
"which is not supported when `thinking` is enabled. This method will raise " "which is not guaranteed when `thinking` is enabled. This method will "
"langchain_core.exceptions.OutputParserException if tool calls are not " "raise an OutputParserException if tool calls are not generated. Consider "
"generated. Consider disabling `thinking` or adjust your prompt to ensure " "disabling `thinking` or adjust your prompt to ensure the tool is called."
"the tool is called."
) )
warnings.warn(thinking_admonition, stacklevel=2) warnings.warn(thinking_admonition, stacklevel=2)
llm = self.bind_tools( llm = self.bind_tools(
[schema], [schema],
# We don't specify tool_choice here since the API will reject attempts to
# force tool calls when thinking=true
ls_structured_output_format={ ls_structured_output_format={
"kwargs": {"method": "function_calling"}, "kwargs": {"method": "function_calling"},
"schema": formatted_tool, "schema": formatted_tool,
@@ -2998,7 +2999,7 @@ class ChatAnthropic(BaseChatModel):
else: else:
llm = self.bind_tools( llm = self.bind_tools(
[schema], [schema],
tool_choice=tool_name, tool_choice=tool_name, # Force tool call
ls_structured_output_format={ ls_structured_output_format={
"kwargs": {"method": "function_calling"}, "kwargs": {"method": "function_calling"},
"schema": formatted_tool, "schema": formatted_tool,