Access Web Tools with Anthropic
Example implementation demonstrating how to use Anthropic's web tool capabilities with the Instructor library for structured outputs from Claude models.
Why it matters
Integrate Anthropic's language models with web tools to enable sophisticated information retrieval and task execution.
Outcomes
What it gets done
Search the web for information.
Extract relevant data from web pages.
Summarize search results.
Interact with web tools via a chatbot interface.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/inst-anthropic-web-tool | bash Capabilities
What this skill does
Searches the web and retrieves relevant sources.
Pulls structured data fields from unstructured text.
Condenses long documents or threads into key takeaways.
Handles multi-turn conversations within a defined domain.
Overview
Anthropic Web Tool
What it does
This is a code example that demonstrates integrating Anthropic's web tool capabilities with the Instructor library. It shows how to structure tool calls and responses when working with Claude models, providing a reference implementation for developers building applications that require both Anthropic's tooling features and Instructor's structured output validation.
How it connects
Use this example when you're building applications that need to call Anthropic's Claude models with web tools and want to ensure type-safe, structured responses. It's particularly useful as a starting point for developers who need to understand how Instructor and Anthropic's tool-calling features work together.
Source README
--- run.py ---
import instructor
from pydantic import BaseModel
Noticed thhat we use JSON not TOOLS mode
client = instructor.from_provider(
"anthropic/claude-3-7-sonnet-latest",
mode=instructor.Mode.JSON,
async_client=False,
)
class Citation(BaseModel):
id: int
url: str
class Response(BaseModel):
citations: list[Citation]
response: str
response_data, completion_details = client.messages.create_with_completion(
messages=[
{
"role": "system",
"content": "You are a helpful assistant that summarizes news articles. Your final response should be only contain a single JSON object returned in your final message to the user. Make sure to provide the exact ids for the citations that support the information you provide in the form of inline citations as [1] [2] [3] which correspond to a unique id you generate for a url that you find in the web search tool which is relevant to your final response.",
},
{
"role": "user",
"content": "What are the latest results for the UFC and who won? Answer this in a concise response that's under 3 sentences.",
},
],
tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 3}],
response_model=Response,
)
print("Response:")
print(response_data.response)
print("\nCitations:")
for citation in response_data.citations:
print(f"{citation.id}: {citation.url}")
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.