Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
`core_parameters`. Close when those GPU runs pass and the qualification
notes in docs/api.md and docs/direct-execution.md are updated.

[ ] Enforce exact decimal numeric range bounds (`minimum`, `maximum`,
`exclusiveMinimum`, `exclusiveMaximum`) in `strict: true` tool schemas
when binary64 conversion or integer adjustment rounds the bound (magnitude
at or above `2^53`, or fractional bounds beyond binary64 precision), or
reject unrepresentable bounds at admission instead of inheriting
llguidance's IEEE 754 binary64 rounding and compilation limits
(helios/src/grammar/strict.rs). Close when every admitted bound of either
sign is enforced at its exact decimal value, any other bound is rejected
with HTTP 400, and docs/api.md is updated.

[ ] Make test_explicit_worker_budget_compiles_and_replays_a_catalog account for
host memory admission. Its nine-worker assertion requires 296 GiB available
under the 32 GiB worker allowance and 8 GiB headroom; smaller hosts admit fewer.
Expand Down
88 changes: 61 additions & 27 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,12 @@ selects required mode. Named selection uses
`{"type":"custom","name":"lookup"}`; namespaced tools use `namespace__name`.
The selected tool must be declared and its type must match.

Named selection presents only the selected tool definition to the model, retaining
conversation history and adding no instructions or decoding constraints.
Named selection presents only the selected tool definition to the model,
retaining conversation history and adding no call instructions. Selection by
itself adds no decoding constraint; when the selected function sets
`strict: true`, the request attaches the strict request grammar described
below, while every declared `strict: true` schema must still be admissible
even when its tool is not selected.
Buffered and streaming responses omit ordinary assistant answer text while
preserving reasoning and tool arguments. Usage includes all generated tokens,
including omitted answer text. Every returned call must target the selected tool,
Expand All @@ -716,13 +720,18 @@ starts in `<think>`, and in non-thinking mode their template opens the DSML
tool-call block at the end of the prompt so generation starts inside the
tool-call envelope. In all modes, including DeepSeek thinking mode, completion
validates that generation produced at least one completed call to a declared
tool. Sampling is unchanged; no calls are fabricated
and no retries are attempted. Missing calls, including output truncated before a
complete call, produce HTTP 500 for buffered requests or a terminal error event
for streams. A required-mode stream may deliver partial text before that error, but does not
emit a success terminator. Responses also supports text custom tools by presenting a
JSON `{ "input": string }` function to the model and restoring the custom call on
output. Anthropic's `type: "custom"` uses its ordinary `input_schema` contract.
tool. No calls are fabricated and no retries are attempted. Required mode by
itself adds no decoding constraint; any active `strict: true` function (a
declared `strict: true` function that `tool_choice` permits calling: any such
function under `"auto"` or `"required"`, the named function under named
selection, and none under `"none"`) attaches the strict request grammar
described below. Missing calls, including output truncated before a complete
call, produce HTTP 500 for buffered requests or a terminal error event for
streams. A required-mode stream may deliver partial text before that error, but
does not emit a success terminator. Responses also supports text custom tools
by presenting a JSON `{ "input": string }` function to the model and restoring
the custom call on output. Anthropic's `type: "custom"` uses its ordinary
`input_schema` contract.
Responses namespaces become unique `namespace__name` names in the model template
and regain their namespace on output; ambiguous names and duplicate namespace
declarations are rejected with HTTP 400, and empty namespace wrappers emit no
Expand Down Expand Up @@ -761,24 +770,49 @@ Missing, duplicate, or unknown IDs leave that group in its supplied order.
Results never move across another
assistant message.

Chat Completions and Responses accept `strict: true` for function tools when the
core declares a DeepSeek DSML, Qwen/ChatML function-tag, GLM argument-tag or
TMLv0 tool parser. Strict schemas must declare `"type": "object"` with
`"additionalProperties": false` at the root and on every nested object, list
every declared property in `"required"`, and use supported bounded JSON-schema
keywords (`properties`, `required`, `additionalProperties`, `items`,
`prefixItems`, `minItems`, `maxItems`, `enum`, `const`, `anyOf`, local `$ref`
to `#`, `#/$defs/<name>`, or `#/definitions/<name>`, numeric bounds,
`multipleOf`, `minLength`, `maxLength`, and `pattern`). Function-tag and GLM
argument-tag syntaxes reject top-level properties that mix `"string"` with
any non-string type, including `"null"`. `enum` and `const` may specify a
compatible `type` but cannot be combined with other assertions; numeric `enum`
and `const` literals are parsed at IEEE 754 binary64 precision and must have
magnitude strictly below `2^53` (`9,007,199,254,740,992`, so integer literals
lie in `[-9,007,199,254,740,991, 9,007,199,254,740,991]`; pass larger exact
identifiers or higher-precision decimals as strings). With an active strict
tool, TMLv0 recognizes only declared tool names, including under
`tool_choice: "auto"`.
Chat Completions and Responses accept `strict: true` for function tools when
the core declares a DeepSeek DSML, Qwen/ChatML function-tag, GLM argument-tag,
or TMLv0 tool parser. Every declared `strict: true` schema is validated at
admission even when `tool_choice` is `"none"` or selects another tool. Strict
schemas must declare `"type": "object"` with `"additionalProperties": false`
at the root and on every nested object, list every declared property in
`"required"`, and use supported bounded JSON-schema keywords (`properties`,
`required`, `additionalProperties`, `items`, `prefixItems`, `minItems`,
`maxItems`, `enum`, `const`, `anyOf`, local `$ref` to `#`, `#/$defs/<name>`,
or `#/definitions/<name>`, numeric bounds, `multipleOf`, `minLength`,
`maxLength`, and `pattern`). Function-tag and GLM argument-tag syntaxes reject
top-level properties that mix `"string"` with any non-string type, including
`"null"`. `enum` and `const` may specify a compatible `type` but cannot be
combined with other assertions. Numeric `enum` and `const` literals are parsed
at IEEE 754 binary64 precision and must have magnitude strictly below `2^53`
(`9,007,199,254,740,992`, so integer literals lie in
`[-9,007,199,254,740,991, 9,007,199,254,740,991]`). Use strings for
identifiers or decimal values that must be represented exactly.

Range bounds (`minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`)
are converted to IEEE 754 binary64 by the grammar compiler. For bounds with
magnitude at or above `2^53`, binary64 representation and exclusive-bound
adjustment can round endpoints in either direction, admitting an out-of-range
neighbor or excluding an in-range value: on an `integer` property,
`minimum: 9007199254740993` admits `9007199254740992`,
`exclusiveMinimum: 9007199254740992` admits `9007199254740992`, and
`maximum: 9007199254740993` rejects `9007199254740993`, whereas inclusive
`maximum: 9007199254740992` (`2^53`), `maximum: 1000000000000000000` (`10^18`),
and `maximum: 9223372036854775807` (`2^63 - 1`) accept the endpoint and reject
the next integer. Below `2^53`, integer-valued bounds are exact, while
fractional `number` bounds beyond binary64 precision likewise round to the
nearest binary64 value (for example, `minimum: 0.30000000000000001` admits
`0.3`). Some large bounds fail grammar compilation and are rejected at
admission with HTTP 400, such as `minimum: -9223372036854775808` (`-2^63`) on
`integer` or `minimum: 1152921504606846976` (`2^60`) on `number`. Where an
admitted schema uses bounds with magnitude at or above `2^53`, or fractional
bounds with more than 15 significant digits, validate tool arguments with exact
integer or decimal arithmetic from the raw JSON argument text (rather than
after binary64 JSON parsing) before tool execution. Post-validation catches
over-admission, but cannot recover valid values the grammar excludes.

With an active strict tool, TMLv0 recognizes only declared tool names,
including under `tool_choice: "auto"`.

Object property names cannot contain `<`, `>`, or whitespace. Top-level property
names also exclude control characters, `"`, `'`, `&`, `\`, and `|`.
Expand Down
58 changes: 58 additions & 0 deletions helios/src/grammar/strict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,64 @@ mod tests {
.validate(r#"{"big": 123456789012345678901234567890}"#)
.unwrap();
assert!(grammar.validate(r#"{"big": 0}"#).is_err());

for maximum in [1_000_000_000_000_000_000u64, i64::MAX as u64] {
let schema = json!({"type":"object","additionalProperties":false,
"required":["n"],
"properties":{"n":{"type":"integer","maximum":maximum}}});
let grammar = validate_strict_tool_schema(&compiler, "measure", &schema).unwrap();
grammar.validate(&json!({"n": maximum}).to_string()).unwrap();
assert!(grammar.validate(&json!({"n": maximum + 1}).to_string()).is_err());
}

// Pin documented llguidance =1.9.1 non-exact binary64 rounding and
// admission-refusal outcomes so a dependency update surfaces visibly.
let min_rounded = json!({"type":"object","additionalProperties":false,
"required":["n"],
"properties":{"n":{"type":"integer","minimum":9_007_199_254_740_993u64}}});
let grammar = validate_strict_tool_schema(&compiler, "measure", &min_rounded).unwrap();
grammar.validate(r#"{"n":9007199254740992}"#).unwrap();
assert!(grammar.validate(r#"{"n":9007199254740991}"#).is_err());

let excl_min_boundary = json!({"type":"object","additionalProperties":false,
"required":["n"],
"properties":{"n":{"type":"integer","exclusiveMinimum":9_007_199_254_740_992u64}}});
let grammar =
validate_strict_tool_schema(&compiler, "measure", &excl_min_boundary).unwrap();
grammar.validate(r#"{"n":9007199254740992}"#).unwrap();
assert!(grammar.validate(r#"{"n":9007199254740991}"#).is_err());

let max_rounded = json!({"type":"object","additionalProperties":false,
"required":["n"],
"properties":{"n":{"type":"integer","maximum":9_007_199_254_740_993u64}}});
let grammar = validate_strict_tool_schema(&compiler, "measure", &max_rounded).unwrap();
grammar.validate(r#"{"n":9007199254740992}"#).unwrap();
assert!(grammar.validate(r#"{"n":9007199254740993}"#).is_err());

let frac_rounded: Value = serde_json::from_str(
r#"{"type":"object","additionalProperties":false,"required":["x"],
"properties":{"x":{"type":"number","minimum":0.30000000000000001}}}"#,
)
.unwrap();
let grammar = validate_strict_tool_schema(&compiler, "measure", &frac_rounded).unwrap();
grammar.validate(r#"{"x":0.3}"#).unwrap();
assert!(grammar.validate(r#"{"x":0.29}"#).is_err());

let rejected_int_min = json!({"type":"object","additionalProperties":false,
"required":["n"],
"properties":{"n":{"type":"integer","minimum":i64::MIN}}});
let err = validate_strict_tool_schema(&compiler, "measure", &rejected_int_min)
.err()
.expect("integer minimum -2^63 should fail admission");
assert!(matches!(err, Error::Admission(AdmissionError::Grammar(_))), "{err}");

let rejected_num_min = json!({"type":"object","additionalProperties":false,
"required":["x"],
"properties":{"x":{"type":"number","minimum":1_152_921_504_606_846_976u64}}});
let err = validate_strict_tool_schema(&compiler, "measure", &rejected_num_min)
.err()
.expect("number minimum 2^60 should fail admission");
assert!(matches!(err, Error::Admission(AdmissionError::Grammar(_))), "{err}");
}

#[test]
Expand Down