Claude With The Anthropic Api
← All lessons
Lesson 34Claude With The Anthropic Api

Tool schemas

Summary audio

No audio recap for this lesson.

Study notes

What is JSON Schema?

  • JSON schema is a data validation specification—a set of rules for validating any JSON data
  • Not specific to language models; widely used technology that has existed for many years
  • LLM community adopted it as a convenient standard for tool calling

Structure of a Tool Configuration Object

  • Name: identifier for the tool (e. g. , "get_weather")
  • Description: explains what the tool does, when to use it, and what data it returns
  • Best practice: 3–4 sentences long
  • Input Schema: the actual JSON schema spec describing function arguments

Input Schema Details

  • Specifies each argument the function accepts
  • For each argument, define:
  • Type: data type (e. g. , string, number)
  • Description: explains what the argument controls and how it affects the function
  • Best practice: 3–4 sentences long

Practical Workflow for Creating Schemas

  • Use Claude to generate JSON schemas automatically
  • Prompt Claude with: your tool function + best practices from Anthropic API documentation
  • Copy the generated schema into your code
  • Naming convention: function_name_schema (e. g. , get_current_datetime_schema)

Type Safety in Python

  • Import ToolParam from anthropic. types
  • Wrap your schema dictionary with ToolParam() to prevent type errors later
  • Not strictly required for code to work, but prevents type checking issues

Takeaways

  • JSON Schema is a widely-used data validation standard that the LLM community adopted as a convenient format for tool calling
  • A tool configuration requires a name, description (3–4 sentences), and an input schema that specifies each argument's type and purpose
  • Use Claude to generate JSON schemas automatically by prompting it with your tool function and Anthropic's best practices
  • In Python, wrap schema dictionaries with ToolParam() from anthropic. types to prevent type checking errors
  • Argument descriptions should be 3–4 sentences explaining what the argument controls and how it affects the function
Flashcards 8 cards
Question
click to reveal · ←/→
Answer
click to flip back
Export to Anki (.tsv) ↓
Knowledge check 5 questions