Skip to content

Instantly share code, notes, and snippets.

@glombard
Last active August 18, 2025 01:26
Show Gist options
  • Save glombard/4f6007ed16449c4751360f4c0892dc4c to your computer and use it in GitHub Desktop.
Save glombard/4f6007ed16449c4751360f4c0892dc4c to your computer and use it in GitHub Desktop.
OpenAI API Tool Parameters JSON Schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/openai-api-tool-parameters.schema.json",
"title": "OpenAI Chat Completions — Parameters (Supported JSON Schema Subset)",
"description": "Meta‑schema for validating a tool function's `parameters` object against the subset of JSON Schema supported by OpenAI Structured Outputs and function calling. See: https://platform.openai.com/docs/guides/structured-outputs#supported-schemas",
"type": "object",
"allOf": [
{ "$ref": "#/$defs/ObjectRoot" }
],
"$defs": {
"SchemaNode": {
"type": "object",
"additionalProperties": false,
"properties": {
"title": { "type": "string" },
"description": { "type": "string" },
"type": {
"oneOf": [
{ "enum": ["object", "array", "string", "number", "integer", "boolean", "null"] },
{
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": { "enum": ["object", "array", "string", "number", "integer", "boolean", "null"] }
}
]
},
"const": { "type": ["string", "number", "integer", "boolean", "null"] },
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": { "type": ["string", "number", "integer", "boolean", "null"] }
},
"$ref": { "type": "string" },
"$defs": {
"type": "object",
"additionalProperties": { "$ref": "#/$defs/SchemaNode" }
},
"anyOf": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/SchemaNode" }
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#/$defs/SchemaNode" }
},
"required": {
"type": "array",
"items": { "type": "string" },
"uniqueItems": true
},
"additionalProperties": { "const": false },
"items": { "$ref": "#/$defs/SchemaNode" },
"minItems": { "type": "integer", "minimum": 0 },
"maxItems": { "type": "integer", "minimum": 0 },
"pattern": { "type": "string" },
"format": {
"type": "string",
"enum": [
"date-time",
"time",
"date",
"duration",
"email",
"hostname",
"ipv4",
"ipv6",
"uuid"
]
},
"multipleOf": { "type": "number", "exclusiveMinimum": 0 },
"maximum": { "type": "number" },
"exclusiveMaximum": { "type": "number" },
"minimum": { "type": "number" },
"exclusiveMinimum": { "type": "number" }
},
"allOf": [
{ "not": { "required": ["allOf"] } },
{ "not": { "required": ["oneOf"] } },
{ "not": { "required": ["not"] } },
{ "not": { "required": ["if"] } },
{ "not": { "required": ["then"] } },
{ "not": { "required": ["else"] } },
{ "not": { "required": ["dependentRequired"] } },
{ "not": { "required": ["dependentSchemas"] } },
{
"if": { "properties": { "type": { "const": "object" } }, "required": ["type"] },
"then": { "required": ["additionalProperties"] }
},
{
"if": {
"properties": { "type": { "type": "array", "contains": { "const": "object" } } },
"required": ["type"]
},
"then": { "required": ["additionalProperties"] }
},
{ "if": { "required": ["properties"] }, "then": { "required": ["required"] } },
{ "not": { "properties": { "items": { "type": "array" } }, "required": ["items"] } }
]
},
"ObjectRoot": {
"allOf": [
{ "$ref": "#/$defs/SchemaNode" },
{ "properties": { "type": { "const": "object" } }, "required": ["type"], "$comment": "Root must be an object schema because tool arguments are an object; top-level anyOf is not allowed." },
{ "not": { "required": ["anyOf"] } }
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment