100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Tool Use, Function Calling & MCP
30 minadvanced

JSON Schema for Tool Parameters

A tool definition's `input_schema` is a JSON Schema object, and it does two jobs at once that are easy to conflate. The first job is mechanical: it constrains what the model is allowed to emit, so a call for `get_weather` cannot show up with `city` as a number or `units` set to a string nobody defined. The second job is communicative: the schema is the last piece of context the model reads before it decides what to write into each field, so every `description` you attach is a direct instruction, not documentation for a human reader who will never see it.

Most tool authors spend their effort on the top-level tool `description` -- what the tool does, when to call it -- and leave the individual `properties` bare, with a `type` and nothing else. That inverts where the leverage is. The top-level description tells the model whether to reach for the tool at all; the per-property description is what stops it from guessing the date format, the units, or which of three plausible IDs a `customer_id` field wants. A bare `"type": "string"` on a field named `date` is an invitation for the model to write `"tomorrow"`.

This lesson treats the schema as a design surface with real trade-offs, not a formality to satisfy a validator. Every keyword you add narrows the space of valid calls, documents intent to the model, and costs tokens on every single request -- three effects from one line of JSON, and the rest of this lesson is about spending that line well.

Analogy🏏Cricket
🏏 Think of it like cricket: when the Indian team management hands a bowler the ball at the death overs of a T20 chase, they don't just say "bowl well." The team sheet and the huddle carry two kinds of information at once. There's the hard constraint -- Jasprit Bumrah is allowed exactly one more over, it must be his fourth, and he cannot bowl two in a row under the rules -- and there's the guidance layered on top: "yorker at leg stump, they've got two left-handers who struggle with the low full ball, keep it inside the last two overs's field restrictions." The rule about one bowler per over is like a JSON Schema constraint: it simply cannot be violated, no matter how good the intent. The huddle's instructions are like a `description` field: nothing stops Bumrah from ignoring them and bowling a bouncer instead, but a specific, well-worded instruction is what makes him bowl the yorker instead of guessing. A captain who only enforces the overs-per-bowler rule and never briefs the plan gets a legal over that goes for 18 runs -- valid, but wrong. The schema's `type` and `required` fields are the overs-per-bowler rule; its `description` fields are the huddle. Skip the huddle and you've only solved half the problem.
Lesson 4 of 35
0% complete