Schema projection matrix

Copy Markdown

ToolCall.Emit.Schema projects the provider-neutral ToolCall.IR into JSON Schema. The target emitters then adapt that schema to their wire format. This file is the canonical description of what survives each projection. The emitters are authoritative; the tests in test/projection_test.exs pin the cells below.

Wire envelopes

OpenAIAnthropicMCPGemini
Shape{"type":"function","function":{...}}{name, description, input_schema}{name, description, inputSchema}{name, description, parameters} in functionDeclarations
Top levelmust be an objectany JSON Schemaan object schema (type: "object")an object schema (type: "OBJECT")
Type casinglowercase JSON Schemalowercase JSON Schemalowercase JSON Schemauppercase OpenAPI Type enum
Nullability["T", "null"]["T", "null"] / anyOfsame as OpenAInullable: true
Who parses argumentsyou (a JSON string)the provider (input arrives decoded)variesthe provider (a functionCall map)

Targets

ConstructOpenAIOpenAI strictOpenAI fine-tunedAnthropicMCPGemini
unionanyOfanyOfanyOfanyOfanyOfanyOf; a null branch becomes nullable: true
numeric boundskeptkeptdroppedkeptkeptkept
pattern / formatkeptkeptdroppedkeptkeptkept; non-string enums are dropped
minItems / maxItemskeptkeptdroppedkeptkeptkept
$ref / $defskeptkeptkeptkeptkeptrejected; a recursive parameter raises
tuple positionsprefixItemsdroppeddroppedprefixItemsprefixItemsdropped
open objectopenclosedclosedopenopenadditionalProperties dropped
:any / :unsupported{}{}{}{}{}{}

OpenAI strict means strict: true. OpenAI fine-tuned means strict: :fine_tuned, which also implies the strict shape; it drops pattern, format, numeric bounds and array bounds because fine-tuned models reject them. MCP passes strict: true through to the shared schema and therefore closes objects; MCP has no strict flag of its own. Gemini ignores strict and adapts the shared schema to its OpenAPI 3.0 subset.

Target-specific notes

OpenAI

The normal target emits the shared JSON Schema inside {"type":"function","function":{...}}. strict: true adds the flag, makes every property required, widens optional values to ["T","null"], and closes every object. Tuple positions are dropped in strict mode because OpenAI rejects prefixItems; minItems and maxItems remain. strict: :fine_tuned renders the same shape without pattern, format, numeric bounds or array bounds.

Anthropic

Anthropic receives the shared schema as input_schema; strict is not part of its tool definition. prefixItems, $ref/$defs, bounds, patterns and formats are preserved.

MCP

MCP receives the shared schema as inputSchema. It is plain JSON Schema and has no strict flag, but strict: true still renders the closed subset, which is valid JSON Schema. strict: :fine_tuned is OpenAI-only and raises for MCP instead of applying the fine-tuned drops. MCP itself does not add constraints.

Gemini

Gemini's parameters is a 22-field OpenAPI 3.0 subset, not JSON Schema. It has no additionalProperties, $ref/$defs, oneOf, prefixItems or const. The emitter:

  • drops additionalProperties, so an object stays open;
  • drops prefixItems, so a tuple keeps only minItems/maxItems;
  • drops non-string enums;
  • collapses a null anyOf branch into nullable: true;
  • raises for a recursive parameter or a null-only schema instead of emitting an invalid schema.

parametersJsonSchema accepts full JSON Schema but is not emitted by ToolCall.emit/3.

ToolCall.Schema.Gemini.to_gemini/2 exposes the same transformation for a schema that was not derived from ToolCall.IR. Its :on_ref option is :raise (default), :drop, or :inline for non-recursive local $defs; oneOf, const, allOf and not raise because Gemini cannot express them. The root must be an object schema, and a multi-type type array raises instead of widening to {}.

Current IR limits

ToolCall.IR.Type has no intersection or negation kind, and no emitter writes allOf or not; Gemini's subset rejects both. TypeExpr therefore lowers a set operation only when the result is representable exactly, through ToolCall.TypeExpr.Projection:

OperationLowered exactlyDegrades to :unsupported
:any / :none identityyes—
integer ranges and integer()overlap, emptiness—
literals and enumsoverlap, difference, narrowing against primitives—
mapsfields and additionalProperties merge, including open/closed sides and optional keysinexact field types
tuplessame-arity position-wise merge; tuple() is the identity; different arity is :none—
identical ref / remotethe node itselfdifferent targets
stringspattern/format/source narrowing when they agree; literals and enums are filtered by the patterntwo different patterns, formats, or sources
and not <range>split into at most two ranges—
and not <union>each variant subtracted in turn—
disjoint primitive kinds:noneother disjoint kinds, provider types
bare complement (not t)—no exact JSON Schema form

An inexact operation yields {:unsupported, :intersection} (or :negation) and the build warns with the existing "no JSON representation" message. It is never silently widened to anyOf or any, because that would tell the model the wrong contract.

Subtraction is exact for integer ranges, literals and enums, tuples (partitioned by the first differing position), and unions. Map, ref, remote, and arbitrary string-constraint subtraction stay :error; JSON Schema cannot carry the resulting complement without a not.

A future native type source that needs more than these cases must either add an IR representation with emitter tests or report a diagnostic.