-
Notifications
You must be signed in to change notification settings - Fork 158
Open
Description
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}")
Metadata
Metadata
Assignees
Labels
No labels