[GH-ISSUE #901] Anthropic Tool Calling and Structured Output #116

Closed
opened 2026-02-17 17:19:12 -05:00 by yindo · 2 comments
Owner

Originally created by @nikbot05 on GitHub (Oct 14, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/901

The following documentation does not return accurate results when I ask questions about current events. It does not seem to be the correct way of using tool calling and structured output.

Please direct me to the correct way to use structured output and anthropic tools as well as fix this documentation.

https://python.langchain.com/docs/integrations/chat/anthropic/

from pydantic import BaseModel, Field
from langchain_anthropic import ChatAnthropic


# Define structured output schema
class ResearchResult(BaseModel):
    """Structured research result from web search."""

    topic: str = Field(description="The research topic")
    summary: str = Field(description="Summary of key findings")
    key_points: list[str] = Field(description="List of important points discovered")


# Configure web search tool
websearch_tools = [
    {
        "type": "web_search_20250305",
        "name": "web_search",
        "max_uses": 10,
    }
]

llm = ChatAnthropic(model="claude-3-5-sonnet-20241022")

# Correct order: bind tools first, then structured output
llm_with_search = llm.bind_tools(websearch_tools)
research_llm = llm_with_search.with_structured_output(ResearchResult)

# Now you can use both web search and get structured output
result = research_llm.invoke("Research the latest developments in quantum computing")
print(f"Topic: {result.topic}")
print(f"Summary: {result.summary}")
print(f"Key Points: {result.key_points}")
Originally created by @nikbot05 on GitHub (Oct 14, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/901 The following documentation does not return accurate results when I ask questions about current events. It does not seem to be the correct way of using tool calling and structured output. Please direct me to the correct way to use structured output and anthropic tools as well as fix this documentation. https://python.langchain.com/docs/integrations/chat/anthropic/ ```python from pydantic import BaseModel, Field from langchain_anthropic import ChatAnthropic # Define structured output schema class ResearchResult(BaseModel): """Structured research result from web search.""" topic: str = Field(description="The research topic") summary: str = Field(description="Summary of key findings") key_points: list[str] = Field(description="List of important points discovered") # Configure web search tool websearch_tools = [ { "type": "web_search_20250305", "name": "web_search", "max_uses": 10, } ] llm = ChatAnthropic(model="claude-3-5-sonnet-20241022") # Correct order: bind tools first, then structured output llm_with_search = llm.bind_tools(websearch_tools) research_llm = llm_with_search.with_structured_output(ResearchResult) # Now you can use both web search and get structured output result = research_llm.invoke("Research the latest developments in quantum computing") print(f"Topic: {result.topic}") print(f"Summary: {result.summary}") print(f"Key Points: {result.key_points}") ```
yindo closed this issue 2026-02-17 17:19:12 -05:00
Author
Owner

@nikbot05 commented on GitHub (Oct 16, 2025):

The new docs don't have an example of using tool calling and structured output. Is this simply not supported?

@nikbot05 commented on GitHub (Oct 16, 2025): The new docs don't have an example of using tool calling and structured output. Is this simply not supported?
Author
Owner

@mdrxy commented on GitHub (Nov 14, 2025):

Support was just announced by Anthropic; https://docs.claude.com/en/docs/build-with-claude/structured-outputs#why-use-structured-outputs

We are working to support this ASAP

@mdrxy commented on GitHub (Nov 14, 2025): Support was just announced by Anthropic; https://docs.claude.com/en/docs/build-with-claude/structured-outputs#why-use-structured-outputs [We are working to support this ASAP](https://github.com/langchain-ai/langchain/pull/33980)
yindo changed title from Anthropic Tool Calling and Structured Output to [GH-ISSUE #901] Anthropic Tool Calling and Structured Output 2026-06-05 17:25:08 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#116