From 77941c45b0a8e56c1bc61bead02b16941348c80a Mon Sep 17 00:00:00 2001 From: Joshua Cartu Date: Thu, 3 Dec 2026 12:44:34 +0100 Subject: [PATCH] docs/api: enumerate accepted response_format JSON Schema keywords Structured-output JSON Schema constraints (`response_format` with `type: "json_schema"` on Chat Completions and Completions, `text.format` on Responses, and `output_config.format` on Messages) validate every schema node against a closed keyword allowlist in `validate_schema_nodes` (`helios/src/grammar.rs`), rejecting unsupported keywords such as `deprecated`, `nullable`, and `uniqueItems` with HTTP 400. Previously, `docs/api.md` documented the strict function-tool keyword subset but did not list the accepted keywords or node limits for structured-output JSON schemas, so clients could not determine which keywords are permitted without inspecting `helios/src/grammar.rs`. Documenting the exact allowlist in `docs/api.md` without altering `validate_schema_nodes` preserves the closed allowlist rule while giving API callers an accurate specification. Before this change, the output-constraint section of `docs/api.md` stated that JSON output formats constrain the final answer and include the schema in the system prompt, without specifying the accepted JSON Schema keywords, external `$ref` rejection, or schema size, depth, and node bounds. After this change, `docs/api.md` enumerates all 42 accepted keywords in `validate_schema_nodes`, grouped into 29 structural and constraint keywords (`$ref` with same-document `#` references only, `$defs`, `definitions`, `type`, `const`, `enum`, `anyOf`, `oneOf`, `allOf`, `properties`, `patternProperties`, `additionalProperties`, `required`, `minProperties`, `maxProperties`, `items`, `prefixItems`, `additionalItems`, `minItems`, `maxItems`, `minLength`, `maxLength`, `pattern`, `format`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, and `multipleOf`) and 13 metadata and annotation keywords (`$anchor`, `$schema`, `$id`, `id`, `$comment`, `title`, `description`, `default`, `readOnly`, `writeOnly`, `examples`, `contentMediaType`, and `contentEncoding`), and notes that any other keyword (such as `deprecated`, `nullable`, `uniqueItems`, or compiler extensions like `x-guidance`), external `$ref` targets, and schemas exceeding 262,144 bytes, depth 64, or 8,192 nodes return HTTP 400. API callers now have a complete, present-state reference for accepted structured-output JSON Schema keywords and admission bounds, with zero changes to runtime validation, grammar compilation, or model core compatibility. Validation: - Verified programmatic 1:1 set parity between `validate_schema_nodes` in `helios/src/grammar.rs` at `3d1614cc` and the enumerated keywords in `docs/api.md` (42 code keywords == 42 documented keywords: 29 structural and constraint keywords plus 13 metadata and annotation keywords, zero missing, zero extra, zero duplicates). - Verified `MAX_GRAMMAR_BYTES` (262,144), `MAX_SCHEMA_DEPTH` (64), `MAX_SCHEMA_NODES` (8,192), and protocol field wiring in `helios/src/grammar.rs` and `helios/src/server/protocol/decode.rs`. - Ran `git diff --check` (zero whitespace issues) and confirmed `git diff --stat` modifies only `docs/api.md`. - Unrun checks: no Rust, Python, simulator, formal, or GPU test suites were run because this commit modifies documentation only. Refs #449 Signed-off-by: Joshua Cartu Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b --- docs/api.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/api.md b/docs/api.md index 6a3c8b466..13c014143 100644 --- a/docs/api.md +++ b/docs/api.md @@ -924,6 +924,23 @@ custom stops cannot be combined with output constraints. For conversational JSON output, the schema and a JSON-only formatting instruction are included in the system prompt as well as enforced by token masks. +JSON Schema output constraints (`response_format` with `type: "json_schema"` on +Chat Completions and Completions, `text.format` on Responses, and +`output_config.format` on Messages) validate every schema node against a closed +keyword allowlist before grammar compilation. Accepted structural and constraint +keywords are `$ref` (same-document `#` references only), `$defs`, `definitions`, +`type`, `const`, `enum`, `anyOf`, `oneOf`, `allOf`, `properties`, +`patternProperties`, `additionalProperties`, `required`, `minProperties`, +`maxProperties`, `items`, `prefixItems`, `additionalItems`, `minItems`, +`maxItems`, `minLength`, `maxLength`, `pattern`, `format`, `minimum`, `maximum`, +`exclusiveMinimum`, `exclusiveMaximum`, and `multipleOf`. Accepted metadata and +annotation keywords are `$anchor`, `$schema`, `$id`, `id`, `$comment`, `title`, +`description`, `default`, `readOnly`, `writeOnly`, `examples`, +`contentMediaType`, and `contentEncoding`. Any other keyword (such as +`deprecated`, `nullable`, `uniqueItems`, or compiler extensions like +`x-guidance`), external `$ref` targets, and schemas exceeding 262,144 bytes, +depth 64, or 8,192 nodes return HTTP 400. + String stops (`stop`, or `stop_sequences` on Messages) accept at most four nonempty strings totaling at most 4096 UTF-8 bytes. Token stops (`stop_token_ids` and `stop_token_sequences`) accept at most sixteen nonempty