Sub topic 16
What differs between providers' schema support
This chapter assumes you can read JSON Schema basics (string, integer, object, array) and short Python examples. It also assumes you have called an LLM API with tools at least once. The core ideas in this tutorial carry across providers: a name, a description, and a JSON Schema for the arguments. The details around that core are where providers differ.
The same definition in different wrappers
Providers wrap the schema in different envelopes. The search_orders tool from earlier chapters uses the Anthropic layout, where the schema sits under input_schema. OpenAI-style APIs call that field parameters and nest the definition inside a function object. Gemini-style APIs use function_declarations with their own field names.
The table shows the typical differences. Check your provider's current documentation, because these details change between versions.
| Concern | Anthropic-style | OpenAI-style | Gemini-style |
|---|---|---|---|
| Schema field | `input_schema` | `parameters` | `parameters` |
| Envelope | Flat tool object | `{"type": "function", "function": {...}}` | Inside `function_declarations` |
| Where the call arrives | A `tool_use` content block | A `tool_calls` entry | A `functionCall` part |
| How arguments arrive | Parsed JSON object | JSON string you must parse | Parsed object |
The third and fourth rows matter in code. With OpenAI-style responses, arguments arrive as a string, so you must call json.loads and handle a parse failure.
Schema keywords are not equally supported
Each provider accepts a subset of JSON Schema. Common gaps include:
- Composition keywords such as
oneOf,anyOf, andallOf. - Reference keywords such as
$refand$defs. - Constraints such as
pattern,minimum,maximum, andformat. - Rules for optional fields. Some strict modes require every property to be listed in
required, and expect you to express "optional" as a type that allowsnull.
Some providers also offer a strict mode that guarantees the arguments match the schema. Strict mode usually narrows the allowed keywords further. A constraint such as maximum: 50 may be rejected, or accepted but not enforced.
Designing for the lowest common denominator
If you target more than one provider, write the schema in a portable core:
- Use plain types:
string,integer,number,boolean,array,object. - Use
enumfor closed sets. - Put format and range rules in the description as well as in keywords. The
created_afterparameter says "YYYY-MM-DD" in its text for this reason. - Avoid
$refand deep nesting where you can. - Keep one tool definition in your own code and generate each provider's envelope from it.
The sketch below shows step 5.
def to_anthropic(tool: dict) -> dict:
return {
"name": tool["name"],
"description": tool["description"],
"input_schema": tool["schema"],
}
def to_openai(tool: dict) -> dict:
return {
"type": "function",
"function": {
"name": tool["name"],
"description": tool["description"],
"parameters": tool["schema"],
},
}The adapter keeps the name, description, and schema identical. Only the wrapper changes.
Test per provider
The same description can lead to different tool choices on different models. Run the evaluation loop from the testing chapter once per provider and model. Do not assume results transfer.
Exercise
Your schema uses maximum: 50 on limit, and the provider accepts it. Why should you still check limit in your tool code?
Show answer
Providers support different subsets of JSON Schema, and some accept a keyword without enforcing it. The model can also send a value outside the range. Validating on the server guarantees the limit holds on every provider.