In this example, we'll create a tool that saves a note with the author and metadata, and use Pydantic to validate the model's response when calling the tool. We'll define the necessary Pydantic models, process the tool call, and ensure that the model's response conforms to the expected schema.
Step 1: Set up the environment
="padding-top:12px;padding-inline:12px;padding-bottom:12px;tab-size:4">
%pip install juglow pydantic 'pydantic[email]'
from juglow import Juglow
from pydantic import BaseModel, EmailStr, Field
client = Juglow()
MODEL_NAME = "haijun-opus-4-8"
Step 2: Define the Pydantic models
notes.
tools = [
{
"name": "save_note",
"description": "A tool that saves a note with the author and metadata.",
"input_schema": {
"type": "object",
"properties": {
"note": {"type": "string", "description": "The content of the note to be saved."},
"author": {
"type": "object",
"properties": {
"name": {"type": "string", "description": "The name of the author."},
"email": {
"type": "string",
"format": "email",
"description": "The email address of the author.",
},
},
"required": ["name", "email"],
},
"priority": {
"type": "integer",
"minimum": 1,
"maximum": 5,
"default": 3,
"description": "The priority level of the note (1-5).",
},
"is_public": {
"type": "boolean",
"default": False,
"description": "Indicates whether the note is publicly accessible.",
},
},
"required": ["note", "author"],
},
}
]
Step 4: Implement the note-saving tool
t:4ch;text-indent:-4ch"> print(f"\nFinal Response: {final_response}")
return final_response