Skip to content

Document strict tool selection and numeric range precision - #461

Open
jcartu wants to merge 1 commit into
NVIDIA:mainfrom
jcartu:pr/strict-numeric-bounds
Open

jcartu wants to merge 1 commit into
NVIDIA:mainfrom
jcartu:pr/strict-numeric-bounds

Conversation

@jcartu

@jcartu jcartu commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Why

Named and required tool_choice modes do not by themselves constrain token sampling, while compile_strict_validators compiles every declared strict: true function schema at request admission regardless of tool_choice (including unselected tools and tool_choice: "none"). Separately, strict numeric enum and const literals are capped strictly below 2^53, whereas llguidance =1.9.1 converts minimum, maximum, exclusiveMinimum, and exclusiveMaximum to IEEE 754 binary64 (and adjusts exclusive integer bounds with + 1.0 / - 1.0 before casting to i64), which can round endpoints in either direction (for bounds with magnitude at or above 2^53, or fractional number bounds beyond binary64 precision) or fail grammar compilation. Rejecting every range bound with magnitude at or above 2^53 at admission would reject inclusive integer maxima such as 9223372036854775807 (2^63 - 1) that the grammar enforces exactly; documenting the admission scope, bidirectional binary64 rounding cases, and admission-refused range bounds preserves valid large maxima without overstating exactness.

What changed

Before this change, docs/api.md stated that named selection adds no decoding constraints and that required mode leaves sampling unchanged, did not define an active strict: true function tool or state that unselected and disabled strict schemas are validated at admission, and did not describe IEEE 754 binary64 range-bound rounding or admission-refused range bounds. After this change:

  • docs/api.md: states that named and required selection add no decoding constraint by themselves (preserving the Jinja-template, TMLv0, and native DeepSeek V4/V4.1 prompt-rendering split from docs: document DeepSeek V4/V4.1 behavior for tool_choice required #686); defines an active strict: true function tool once; states that every declared strict: true schema is validated at admission even when unselected or under tool_choice: "none"; separates the < 2^53 enum/const literal cap from IEEE 754 binary64 range-bound conversion; documents bidirectional rounding for bounds with magnitude at or above 2^53 (minimum: 9007199254740993, exclusiveMinimum: 9007199254740992, maximum: 9007199254740993) and fractional number bounds beyond binary64 precision (minimum: 0.30000000000000001), exact inclusive maxima (2^53, 10^18, 2^63 - 1), and admission-refused bounds (minimum: -9223372036854775808 on integer, minimum: 1152921504606846976 on number returning HTTP 400); and advises exact integer or decimal validation from the raw JSON argument text before tool execution while noting that post-validation catches over-admission but cannot recover valid values excluded by the grammar.
  • docs/TODO.txt: adds an entry tracking exact decimal enforcement or HTTP 400 admission rejection of strict: true numeric range bounds when binary64 conversion or integer adjustment rounds the bound (magnitude at or above 2^53, or fractional bounds beyond binary64 precision), with a closure criterion covering both signs.
  • helios/src/grammar/strict.rs: extends strict_bounds_do_not_round_integers_or_fractional_multiples to pin exact inclusive integer maxima (10^18, i64::MAX, alongside the existing 2^53 check), bidirectional integer rounding (minimum: 9007199254740993, exclusiveMinimum: 9007199254740992, maximum: 9007199254740993), fractional binary64 rounding (minimum: 0.30000000000000001), and AdmissionError::Grammar rejection of minimum: -2^63 on integer and minimum: 2^60 on number.

Claimed result

Runtime admission and decoding behavior are unchanged relative to main (zero new HTTP 400s). The API reference and docs/TODO.txt accurately describe strict-tool admission scope, active-grammar attachment, and IEEE 754 binary64 numeric range behavior, and unit tests fail visibly if a dependency update alters the documented outcomes.

Evidence

  • On branch head 9e1c4701 (rebased onto main cfb72093), cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib grammar::strict on Linux x86_64 CPU (rustc 1.100.0): 28 passed, 0 failed, 1 ignored (including strict_bounds_do_not_round_integers_or_fractional_multiples).
  • On branch head 9e1c4701 (rebased onto main cfb72093), cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib server::request::tests::ignored_strict_tools_still_require_compiler_admissible_schemas on Linux x86_64 CPU (rustc 1.100.0): 1 passed, 0 failed.
  • Material limitation: no production runtime code changed; GPU serving, simulator, and formal checks were not run.

Discord: jcartu

@yatesdr yatesdr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Checked a640a30. The docs/api.md changes settle the two sentences our #418 review flagged: named and required selection now say a strict function still attaches its grammar.

The admission rule refuses more than the gap it closes. On main 6d6fe0c we ran a scratch test through validate_strict_tool_schema and TextGrammar::validate (aarch64 Linux, CPU only), on integer properties:

Bound Value tried Result on main
exclusiveMinimum: 9007199254740992 9007199254740992 accepted (schema forbids it)
minimum: 9007199254740993 9007199254740992 accepted (schema forbids it)
maximum: 9007199254740992 9007199254740992 / 9007199254740993 accepted / rejected (exact)
maximum: 1000000000000000000 10^18 / 10^18 + 1 accepted / rejected (exact)
maximum: 9223372036854775807 2^63 - 1 / 2^63 accepted / rejected (exact)

minimum: -9223372036854775808 on integer, and minimum: 2^60 on number, are already refused by llguidance with a range error.

  1. Exact bounds become HTTP 400s. Rejecting every magnitude at or above 2^53 also refuses the exact rows above, including the int64 limits that generated schemas emit. The PR changes main's own test from maximum: 9007199254740992 to 9007199254740991 so that it passes. Please refuse only the bounds llguidance rounds: an exclusive integer bound at or above 2^53, and a bound whose value does not survive conversion to f64 and back. Or leave admission as it is and document the limit, which docs/api.md now states.
  2. Compatibility. Whatever remains, please say in the description which requests accepted today now return HTTP 400.

Nit: the commit message's section on #418's timing provenance describes #418's evidence, not this change, and cites a commit that is not in this repository. It belongs on #418's thread, if anywhere.

@jcartu jcartu changed the title Bound strict function-tool numeric range keywords below 2^53 Document strict tool selection and numeric range precision Nov 23, 2026
@jcartu

jcartu commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@yatesdr I took the documentation alternative from your review. At e831b49 the net runtime diff against the PR base is empty: no new HTTP 400s. The original inclusive 2^53 test is unchanged, and the new regression accepts 10^18 and i64::MAX at the endpoint and rejects each successor. The strict grammar suite passed on x86_64 (28 passed, 1 ignored). The API docs identify the two rounding cases rather than claiming they are fixed; the PR description no longer cites unrelated timing results. Ready for another look.

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 461
Case File Intake Report

To opt out, include #autobot:ignore in the PR or any comment.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Full Review

Changes Requested

Blockers:

  • None.

Should fix:

  • Admission scope is unstated. The new sentences (docs/api.md:522-525, :544-546) read as if only the selected strict tool matters, but compile_strict_validators filters every strict tool with no tool_choice term (helios/src/server/request.rs:94, called unconditionally at :125), so an inadmissible strict schema is an HTTP 400 even under tool_choice: "none". → Add one clause: every declared strict: true schema must be admissible even when its tool is not selected.
  • The documented rounding deviation has no docs/TODO.txt entry. docs/api.md:605-612 records a live gap; AGENTS.md:47-55 requires unresolved defects there, not in design documents, and no entry exists. → Add one naming the missing condition and its removal criterion.
  • The rounding examples are pinned by no test. The added test (helios/src/grammar/strict.rs:3888-3898) covers only exact inclusive maximum; the minimum/exclusiveMinimum outcomes at api.md:607-609 are asserted nowhere against llguidance =1.9.1 (helios/Cargo.toml:62). → Extend the test so a dependency bump that fixes rounding fails visibly.
  • The paragraph omits bounds that are refused, not rounded. Your own table records minimum: -2^63 on integer and minimum: 2^60 on number already returning a range error (HTTP 400), where "validate in the tool" cannot apply. → Add one sentence and assert those outcomes too.

Nits:

9 nits

  • Fold the new test into strict_bounds_do_not_round_integers_or_fractional_multiples (strict.rs:3005-3025) or move it next to :3025; only i64::MAX is genuinely new.
  • Restore "IEEE 754" at api.md:600-603; the word now appears nowhere under docs/.
  • Rewrap api.md:607 (86 columns vs ~78-80) and drop the unsupported bound + 1 mechanism clause at :608-609.
  • Define "active" once (api.md:545, 614, 639, 644) and prefer "adds no decoding constraint" at :544 over "leaves sampling unconstrained".
  • Add a claimed-result sentence to the description and squash commit e831b496, whose subject describes the branch against its own parent, not main.

To opt out of future reviews, put #autobot:ignore in your response.

@jcartu
jcartu force-pushed the pr/strict-numeric-bounds branch from e831b49 to 31c9020 Compare November 28, 2026 23:30
@jcartu

jcartu commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@flare-autobot Addressed all review items on rebased main:

  • Admission scope & active definition (docs/api.md): Stated that every declared strict: true schema must be admissible even when unselected or under tool_choice: "none", defined an active strict: true function tool once, and switched required mode to "adds no decoding constraint".
  • Tracked gap (docs/TODO.txt): Added an entry for llguidance's IEEE 754 binary64 range-bound rounding and range limits with its closure criterion.
  • Pinned rounding & refused bounds (docs/api.md, helios/src/grammar/strict.rs): Folded the 10^18 and i64::MAX checks into strict_bounds_do_not_round_integers_or_fractional_multiples alongside minimum: 9007199254740993, exclusiveMinimum: 9007199254740992, and admission rejection of minimum: -2^63 (integer) and minimum: 2^60 (number) (27 passed, 1 ignored), restored "IEEE 754", removed the unsupported mechanism clause, wrapped lines, and squashed onto main.

@flare-autobot flare-autobot added area:api Serving API, protocol encoding, tool parsing, and client-visible behavior. documentation Improvements or additions to documentation triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 29, 2026
Named and required `tool_choice` modes do not by themselves constrain token
sampling, while `compile_strict_validators` compiles every declared
`strict: true` tool schema at request admission regardless of `tool_choice`
(including unselected tools and `tool_choice: "none"`). Separately, strict
numeric `enum` and `const` literals are capped strictly below `2^53`, whereas
`llguidance =1.9.1` converts `minimum`, `maximum`, `exclusiveMinimum`, and
`exclusiveMaximum` to IEEE 754 binary64 (and adjusts exclusive integer bounds
with `+ 1.0` / `- 1.0` before casting to `i64`), which can round endpoints in
either direction (for bounds with magnitude at or above `2^53`, or fractional
`number` bounds beyond binary64 precision) or fail grammar compilation.
Rejecting every range bound with magnitude at or above `2^53` at admission
would reject valid inclusive integer maxima such as `2^63 - 1` (`i64::MAX`)
that the grammar enforces exactly; documenting the admission scope,
bidirectional binary64 rounding cases, and admission-refused range bounds
preserves valid large maxima without misstating exactness.

Before this change, `docs/api.md` stated that named selection adds no decoding
constraints and that required mode leaves sampling unchanged, did not define an
active `strict: true` function tool or state that unselected and disabled
strict schemas are validated at admission, and did not describe IEEE 754
binary64 range-bound rounding or admission-refused range bounds. After this
change:
- `docs/api.md`: states that named and required selection add no decoding
  constraint by themselves while preserving the prompt-rendering split across
  Jinja-template, TMLv0, and native DeepSeek V4/V4.1 encoders; defines an
  active `strict: true` function tool once; states that every declared
  `strict: true` schema must be admissible even when unselected or under
  `tool_choice: "none"`; separates the `< 2^53` `enum`/`const` literal cap from
  IEEE 754 binary64 range-bound conversion; documents bidirectional rounding
  for bounds with magnitude at or above `2^53` (`minimum: 9007199254740993`,
  `exclusiveMinimum: 9007199254740992`, `maximum: 9007199254740993`) and
  fractional `number` bounds beyond binary64 precision
  (`minimum: 0.30000000000000001`), exact inclusive maxima (`2^53`, `10^18`,
  `2^63 - 1`), and admission-refused bounds (`minimum: -9223372036854775808` on
  `integer`, `minimum: 1152921504606846976` on `number` returning HTTP 400);
  and advises exact integer or decimal validation from the raw JSON argument
  text before tool execution while noting that post-validation catches
  over-admission but cannot recover values excluded by the grammar.
- `docs/TODO.txt`: adds an entry recording the unresolved `llguidance` IEEE 754
  binary64 range-bound rounding and compilation limits (magnitude at or above
  `2^53`, or fractional bounds beyond binary64 precision) in
  `helios/src/grammar/strict.rs` and its closure criterion covering both signs.
- `helios/src/grammar/strict.rs`: extends
  `strict_bounds_do_not_round_integers_or_fractional_multiples` to pin exact
  inclusive integer maxima (`10^18`, `i64::MAX`, alongside the existing `2^53`
  check), bidirectional integer rounding (`minimum: 9007199254740993`,
  `exclusiveMinimum: 9007199254740992`, `maximum: 9007199254740993`),
  fractional binary64 rounding (`minimum: 0.30000000000000001`), and
  `AdmissionError::Grammar` rejection of `minimum: -2^63` on `integer` and
  `minimum: 2^60` on `number`.

Claimed result: runtime admission and decoding behavior are unchanged relative
to `main` (zero new HTTP 400s); the API reference and `docs/TODO.txt` match
Helios request admission and `llguidance =1.9.1` range behavior, and unit tests
fail visibly if a dependency update alters the documented outcomes.

Evidence: on this change rebased onto `main` (`cfb72093`), ran `cargo test
--locked --release --manifest-path helios/Cargo.toml --features
runtime-core,server --lib grammar::strict` (28 passed, 0 failed, 1 ignored,
including `strict_bounds_do_not_round_integers_or_fractional_multiples`) and
`cargo test --locked --release --manifest-path helios/Cargo.toml --features
runtime-core,server --lib
server::request::tests::ignored_strict_tools_still_require_compiler_admissible_schemas`
(1 passed, 0 failed) on Linux x86_64 CPU (`rustc 1.100.0`). Material
limitation: no production runtime code changed, so GPU serving, simulator, and
formal checks were not run.

Design-Signed-Off-By: Antigravity (Gemini 4); design-review=2e5b
Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com>
@jcartu
jcartu force-pushed the pr/strict-numeric-bounds branch from 31c9020 to 9e1c470 Compare December 5, 2026 01:51
@jcartu

jcartu commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (cfb72093) at 9e1c4701, resolving merge conflicts in docs/api.md (preserving the DeepSeek V4/V4.1 required-mode prompt-rendering documentation from #686) and docs/TODO.txt.

Also tightened the range-bound documentation and tests against llguidance =1.9.1:

  • Scoped range-bound rounding and the docs/TODO.txt closure criterion to bounds with magnitude at or above 2^53 (both signs) and fractional number bounds beyond binary64 precision, added maximum: 9007199254740993 (rejects valid 9007199254740993) and minimum: 0.30000000000000001 (admits 0.3) alongside minimum: 9007199254740993, exclusiveMinimum: 9007199254740992, and exact inclusive maxima (2^53, 10^18, 2^63 - 1), and specified exact integer or decimal validation from the raw JSON argument text while noting post-validation cannot recover values excluded by the grammar.
  • Pinned the refused bounds (minimum: -2^63 on integer, minimum: 2^60 on number) to Error::Admission(AdmissionError::Grammar(_)) (surfaced as HTTP 400 invalid_grammar).

Verified on branch head 9e1c4701 (Linux x86_64 CPU, rustc 1.100.0):

  • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib grammar::strict: 28 passed, 0 failed, 1 ignored.
  • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib server::request::tests::ignored_strict_tools_still_require_compiler_admissible_schemas: 1 passed, 0 failed.

Runtime admission and decoding behavior remain unchanged relative to main (zero new HTTP 400s). Ready for another look from @yatesdr and @flare-autobot.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

All four should-fix items from my 2026-11-24 review are resolved at 9e1c470, and yatesdr's two CHANGES_REQUESTED asks are met by the documentation route he himself offered. The diff's production-code surface is empty — every added Rust line lives inside #[cfg(test)] mod tests (helios/src/grammar/strict.rs:2457, additions at :3033-3089) — and I re-derived each documented behaviour from the code it describes; every claimed outcome holds and the new assertions pin the exact llguidance =1.9.1 results the prose quotes.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 4 · Nits: 4
Walkthrough
  • Admission scope now matches the code. docs/api.md:775-776 states every declared strict: true schema is validated at admission even under tool_choice: "none"; compile_strict_validators filters on tool.strict with no tool_choice term (helios/src/server/request.rs:94), is called unconditionally from prepare_inference_cached (:125) and from helios/src/server/http.rs:264-266, and is pinned by ignored_strict_tools_still_require_compiler_admissible_schemas (request.rs:760-825, loop over ToolChoice::None and Named at :800-803).
  • "Active" is defined once and matches request.rs:230-246: empty under None, the named tool under Named (:236), all tools otherwise, with strict_schema: tool.strict.then_some(...) (:241) and has_active_strict_tool (:247) gating grammar attachment.
  • The refusal class is documented and asserted where it becomes HTTP 400. docs/api.md:805-807 names minimum: -9223372036854775808 on integer and minimum: 1152921504606846976 on number; strict.rs:3075-3089 asserts Error::Admission(AdmissionError::Grammar(_)), which helios/src/server.rs:746 maps to BAD_REQUEST with code invalid_grammar (server.rs:757), via grammar.rs:567-579.
  • Every quoted rounding outcome is pinned, and the pins are non-vacuous. strict.rs:3044-3049 (minimum: 2^53+1 admits 2^53, rejects 2^53-1), :3051-3057 (exclusiveMinimum: 2^53 admits the endpoint), :3059-3064 (maximum: 2^53+1 rejects 2^53+1), :3066-3073 (minimum: 0.30000000000000001 admits 0.3, rejects 0.29), :3033-3040 (10^18 and i64::MAX accept endpoint, reject successor; i64::MAX as u64 + 1 does not overflow) alongside the pre-existing 2^53 case at :3015-3022.
  • The advisory is implementable as written. docs/api.md:808-812 tells clients to validate from raw JSON text; serde_json already has float_roundtrip and raw_value (helios/Cargo.toml:52), and post-validation does consume the raw accumulated arguments (helios/src/server/protocol/encode.rs:612-614).
  • Repo-required tracking exists and the description is honest. docs/TODO.txt:25-33 gives the missing condition and a both-signs closure criterion; the description carries Why / What changed / Claimed result / Evidence plus the explicit limitation, and the branch is squashed to one commit (9e1c4701).
Merge Risk: Low · up to 9e1c470
  • Zero non-test lines changed in helios/: validate_strict_tool_schema (helios/src/grammar/strict.rs:53-145), the range-bound finiteness check (:575-584) and the 1 << 53 cap (:176-192, reached only from const :348 / enum :368) are byte-identical to main, so "zero new HTTP 400s" is structurally true.
  • The admitted/refused split the docs describe is enforced by the pinned dependency, not by moved code: llguidance = "=1.9.1" (helios/Cargo.toml:63), so a bump surfaces as a unit-test failure rather than silent prose drift.
  • Residual risk is documentation drift only; docs/TODO.txt:25-33 tracks the underlying leniency with a closure criterion per AGENTS.md:57-58.
Pre-merge checks: ✅ 4 passed

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

Want a frontier second opinion? PR authors, contributors, and maintainers can comment @flare-autobot super (or @flare-autobot:super) to run a one-time SuperAgent Review on 9e1c470 (~3–4 min; re-adjudicates existing findings without re-running discovery).

To opt out, include #autobot:ignore in your post or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:api Serving API, protocol encoding, tool parsing, and client-visible behavior. documentation Improvements or additions to documentation triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants