The Anthropic API officially supports tool-calling so this workaround is no longer needed. Please use ChatAnthropic with
langchain-anthropic>=0.1.15.langchain-anthropic package, and it also requires the optional dependency defusedxml for parsing XML output from the llm.
Note: this is a beta feature that will be replaced by Anthropic’s formal implementation of tool calling, but it is useful for testing and experimentation in the meantime.
Tool Binding
ChatAnthropicTools exposes a bind_tools method that allows you to pass in Pydantic models or BaseTools to the llm.
Structured Output
ChatAnthropicTools also implements the with_structured_output spec for extracting values. Note: this may not be as stable as with models that explicitly offer tool calling.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.