mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #334] [CLOSED] serve: enforce structured JSON in the native sampler #2583
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2583
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/334
Author: @KadoBOT
Created: 10/1/2026
Status: ❌ Closed
Base:
main← Head:contrib/validated-json-output📝 Commits (2)
ab14d9dserve: validate JSON response formats before deliveryf318e3bEnforce structured JSON in the native sampler📊 Changes
18 files changed (+830 additions, -16 deletions)
View changed files
📝
CMakeLists.txt(+3 -0)📝
Dockerfile(+1 -1)📝
docs/DETAILS.md(+18 -0)➕
docs/structured-output.md(+74 -0)➕
include/strata/core/grammar_mask.hpp(+30 -0)📝
include/strata/core/verify.hpp(+7 -0)📝
include/strata/kernels/sampler.hpp(+4 -0)📝
serve/frontend.py(+6 -0)➕
serve/grammar.py(+83 -0)📝
serve/server.py(+64 -4)➕
serve/structured.py(+154 -0)➕
serve/test_grammar.py(+146 -0)➕
serve/test_structured.py(+141 -0)📝
setup.py(+2 -2)📝
src/core/verify.cpp(+5 -1)📝
src/kernels/cuda/sampler.cu(+9 -0)➕
src/kernels/grammar_mask_test.cpp(+37 -0)📝
src/program/generate.cpp(+46 -8)📄 Description
Clients requesting structured JSON can currently receive successful prose because the OpenAI-compatible endpoint ignores
response_format. This enforcesjson_objectandjson_schemaduring native decoding, so a required field such asvoiceovercannot be omitted from a completed strict response.Behavior
additionalProperties: false. Unsupported or unenforceable schemas return HTTP 400. Only local references are resolved.finish_reason: "length"; OpenAI SDK parse/stream helpers raise their normalLengthFinishReasonError. Independently validate normally completed bodies before the terminal success chunk. Backend invariant failures return HTTP 502 or an SSE error.native_token_mask, constrained decoding and incremental streaming through/v1/status. Require nativegrammar_mask_v1explicitly; do not fall back to prompting on older binaries. Structured formats with tools/MCP remain explicitly unsupported.One generation per request: no retry, repair pass or default insertion. This covers Chat Completions response formats, not the Responses API or provider-specific refusal policies. Native grammar masks currently disable speculative decoding for structured requests, so those requests trade throughput for enforcement.
Validation
grammar_mask_testproves greedy and sampled decoding cannot select forbidden high-probability tokens. Existingsampler_parity --selftestpassed.python -m unittest discover -s serve -p "test_*.py": 87 tests, OK, 3 optional skips. Focused structured/grammar checks: 14 tests, OK. OpenAI SDK checks use a local server and require no cloud key.voiceover,overlapanddelivery; the completed dialogue included all required fields. SDK parse and streaming parse, JSON arithmetic, token-limit handling, invalid-schema 400 and subsequent plain decoding passed.git diff --checkpassed. Model files, local hardware/network settings and the user's H3 node are excluded.Usage and limits:
docs/structured-output.md.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.