Module schema

Module schema 

Source
Expand description

2026-09-26: JSON Schema to EBNF conversion. json_schema_to_ebnf parses the schema into a JsonValue, resolves it into a SchemaSpec (parser*), and emits the EBNF rules (converter, gen_*); json_schema_to_grammar parses that EBNF into GrammarData.

JsonValue keeps object entries in document order, and SchemaSpec::properties is filled in that order. An allOf with more than one schema is generated as any.

Owner: grammar. Invariants: none beyond the types.

Structs§

SchemaConverterOptions
Options controlling JSON-schema -> EBNF conversion. Field meanings match the JSONSchemaToEBNF parameters in the C++ header.
SchemaError
An error raised while converting a JSON Schema document into an EBNF grammar string.

Enums§

JsonFormat
Root output format. Json produces a fully JSON-style grammar; the XML variants produce an XML-style root object with JSON-style inner values (used for tool calling). Mirrors C++ JSONFormat.
JsonValue
An order-preserving JSON value.
SchemaErrorKind
Classification of a schema-conversion failure, mirroring the C++ SchemaErrorType enum.

Functions§

builtin_json_grammar
Build the parsed GrammarData for the builtin-JSON grammar.
builtin_json_grammar_ebnf
Build the EBNF grammar for the “any JSON value” schema ({}).
deepseek_xml_tool_calling_to_ebnf
Convert a function-call parameter schema into a DeepSeek-XML-style EBNF grammar. Port of DeepSeekXMLToolCallingToEBNF.
generate_float_range_regex
Generate a regex matching floats in [start, end] inclusive, each bound None meaning unbounded, with at most precision fractional digits. Port of GenerateFloatRangeRegex.
generate_range_regex
Generate a regex matching integers in [start, end] (inclusive), each bound None meaning unbounded. Port of GenerateRangeRegex.
json_schema_to_ebnf
Convert a JSON Schema string into an EBNF grammar string. Port of the std::string overload of JSONSchemaToEBNF.
json_schema_to_grammar
Convert a JSON Schema string into a parsed GrammarData AST by generating the EBNF and feeding it through the EBNF parser.
json_value_to_ebnf
Convert a JSON Schema document (already parsed into a JsonValue) into an EBNF grammar string. Port of the picojson::value overload of JSONSchemaToEBNF.
minimax_xml_tool_calling_to_ebnf
Convert a function-call parameter schema into a MiniMax-XML-style EBNF grammar. Port of MiniMaxXMLToolCallingToEBNF.
qwen_xml_tool_calling_to_ebnf
Convert a function-call parameter schema into a Qwen-XML-style EBNF grammar. Port of QwenXMLToolCallingToEBNF.

Type Aliases§

SchemaResult
Convenience alias for converter results.