Sub topic 16
What differs between providers' schema support
This chapter assumes you have read the earlier chapters on tool definitions. It also assumes you can read JSON Schema (type, enum, required) and short Python examples. The goal is to help you write tool definitions that survive a move between providers, or that work with more than one provider at once.
What stays the same
Every major provider sends the model the same three things for each tool: a name, a description, and a JSON Schema for the arguments. The advice from earlier chapters applies everywhere. Say what the tool does, when to use it, and when not to. Give each parameter a description and a type. Use enums where the values are a closed set.
What changes is the wrapper around those three things, how strictly the provider enforces the schema, and which schema keywords it accepts. Those differences cause most porting bugs.
Differences in the wrapper
The field that holds the schema has a different name in each API, and the nesting differs too.
| Provider style | Where the tool goes | Schema field | Arguments in the model's call |
|---|---|---|---|
| Anthropic Messages | `tools: [{name, description, input_schema}]` | `input_schema` | Parsed JSON object in a `tool_use` block |
| OpenAI Chat Completions | `tools: [{type: "function", function: {name, description, parameters}}]` | `parameters` | JSON string in `tool_calls[].function.arguments` |
| OpenAI Responses | Flat: `{type: "function", name, description, parameters}` | `parameters` | JSON string in a function call item |
| Google Gemini | `tools: [{functionDeclarations: [{name, description, parameters}]}]` | `parameters` | Parsed object in a `functionCall` part |
Two details cause real bugs:
- Arguments as a string. OpenAI returns arguments as a string that you must parse. Parsing can fail if the model produces malformed JSON, so wrap it in error handling. Anthropic gives you an object already.
- Results go back in different places. Anthropic expects a
tool_resultblock, withis_erroravailable, inside a user message and tied to the call bytool_use_id. OpenAI expects a message with roletooland atool_call_id. Gemini expects afunctionResponsepart. The error-message advice from earlier chapters still applies. You only need to put the text in the right slot.
Treat this table as a snapshot. Field names and options change between API versions, so check the current documentation.
Differences in enforcement
Providers differ most in what happens when the model's output does not match your schema.
- Best-effort mode. The model reads the schema as guidance. It usually follows it, but it can send a string where you wanted an integer, omit a required field, or invent an enum value. This is the default for most providers.
- Strict or constrained mode. Some providers can constrain decoding so the arguments always match the schema. OpenAI calls this
strict: trueon a function. Other providers offer similar options. Strict mode removes most type errors, but it comes with rules about which schemas it accepts.
Strict modes typically impose restrictions such as these:
- Every object must set
additionalPropertiestofalse. - Every property must appear in
required. An optional parameter becomes a required one whose type also allowsnull. - A subset of JSON Schema keywords is supported. Keywords such as
minimum,maximum,minLength, andpatternhave been unsupported in some strict implementations. - Limits apply to nesting depth, total property count, and total enum values.
The exact list varies by provider and changes over time, so do not rely on a list in a tutorial. Look up the current "supported schemas" page for the provider and model you use.
Strict mode does not replace server-side validation. It guarantees the shape of the arguments. It does not guarantee they are correct. "order_id": "ord_9999" matches the schema and still names an order that does not exist. Keep the checks from the validation chapter.
Differences in keyword support
Even in best-effort mode, providers treat schema keywords differently:
- Some providers accept full JSON Schema. Others accept a subset based on OpenAPI 3.0. Gemini's
parametersfield has historically been an OpenAPI-style subset, and newer options for passing plain JSON Schema have been added. - Keywords such as
$ref,oneOf,anyOf,allOf,format, andadditionalPropertiesmay be ignored, rejected, or only partly supported. - A keyword the provider ignores does not raise an error. The model just never sees the constraint. A schema with
"maximum": 50can behave as if it had no maximum.
Two defensive habits follow from this:
- Repeat important constraints in the description. The description is plain text, so every provider passes it through. Write "Between 1 and 50. Defaults to 10." even when the schema also has
minimumandmaximum. - Prefer simple schemas. Flat objects with strings, integers, booleans, and enums work everywhere. Deep nesting, unions, and recursive references are where providers diverge.
Keeping one source of truth
If you support several providers, do not hand-write each definition. Keep one neutral definition and generate each provider's format from it. The following example converts one definition to the Anthropic and OpenAI shapes. It also rewrites the schema for a strict mode: optional fields become nullable and required, additionalProperties is set to false, and numeric bounds move into the description.
import copy
import json
NEUTRAL = {
"name": "search_orders",
"description": "Search a customer's orders by status. Returns newest first.",
"schema": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"description": "Customer ID, for example 'cus_4821'.",
},
"status": {
"type": "string",
"enum": ["pending", "shipped", "delivered", "cancelled"],
"description": "Only return orders with this status.",
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"description": "Maximum number of orders to return.",
},
},
"required": ["customer_id"],
},
}
def to_anthropic(tool):
return {
"name": tool["name"],
"description": tool["description"],
"input_schema": tool["schema"],
}
def make_strict(schema):
schema = copy.deepcopy(schema)
required = set(schema.get("required", []))
for name, prop in schema["properties"].items():
for key in ("minimum", "maximum"):
if key in prop:
note = f" ({key}: {prop.pop(key)})"
prop["description"] += note
if name not in required:
prop["type"] = [prop["type"], "null"]
if "enum" in prop:
prop["enum"] = prop["enum"] + [None]
schema["required"] = list(schema["properties"])
schema["additionalProperties"] = False
return schema
def to_openai(tool, strict=False):
schema = make_strict(tool["schema"]) if strict else tool["schema"]
function = {
"name": tool["name"],
"description": tool["description"],
"parameters": schema,
}
if strict:
function["strict"] = True
return {"type": "function", "function": function}
print(json.dumps(to_openai(NEUTRAL, strict=True), indent=2))This sketch handles only top-level properties. A production version must walk nested objects and array items too. When you use the strict output, remember that the model now sends null for omitted optional fields. Your handler must treat null the same as "not provided".
Testing across providers
Models from different providers can pick different tools for the same prompt. A description that works well on one model can still be ambiguous to another. Run the same evaluation cases against each provider you support, and track the pass rate per provider. A drop on one provider usually points to one of these causes:
- A keyword that provider ignores.
- A description that relies on wording one model reads differently.
- A strict-mode rewrite that changed behavior, such as
nullvalues you do not handle.
Decision criteria
- Use a single provider with simple schemas: write the definition in that provider's format and keep the schema flat.
- Support several providers: keep a neutral definition and generate each format. Put important constraints in descriptions as well as in the schema.
- Need guaranteed argument shape: use strict mode where it exists. Accept its restrictions, and handle
nullfor optional fields. - Need rich constraints such as patterns and ranges: enforce them on the server. Do not depend on any provider honoring them.
Exercise
You move a tool from a best-effort mode to a provider's strict mode. The tool has an optional status enum and an integer limit with minimum: 1 and maximum: 50. Name three changes you must make, and one thing your handler must now do.
Show answer
(1) Make status and limit appear in required, with their types allowing null (and null added to the enum for status). (2) Set additionalProperties to false on the object. (3) Remove minimum and maximum if the provider's strict mode does not support them, and state the 1 to 50 range in the description. The handler must treat null as "not provided" and still check the range on the server, because strict mode guarantees only the shape of the arguments.