Skip to content

SWF(bug): enforce text.format schemas in the Responses API - #65

Merged
maplepaladin73 merged 2 commits into
mainfrom
devin/1795385672-responses-text-format
Nov 23, 2026
Merged

maplepaladin73 merged 2 commits into
mainfrom
devin/1795385672-responses-text-format

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

/v1/responses now enforces text.format (json_schema / json_object) the same way /v1/chat/completions enforces response_format. Before this change it ignored the format without any error.

Root cause: lower_responses_to_chat in crates/spark-server/src/openai/responses_lowering.rs hard-coded response_format: None, so the schema never reached the chat pipeline's grammar constraint.

Fix: a small lower_text_format helper maps Responses' flat {type:"json_schema", name, schema, strict} onto chat's nested {type:"json_schema", json_schema:{...}} and deserializes it into the existing ResponseFormat. No new schema types were added. json_object passes through unchanged, and text or an absent format stays unconstrained. A malformed format now gets a 400 invalid text.format: ..., which matches what chat does with a malformed response_format.

Rebased onto main after #63 (the --bin spark test build fix) merged.

Test plan

New regression tests are in crates/spark-server/src/openai/tests/responses_text_format.rs. They check that json_schema keeps name, description, schema and strict; that json_object is kept; that text is unconstrained; and that a malformed format is rejected.

Before the fix:

test openai::tests::responses_text_format::responses_text_format_unconstrained ... ok
test openai::tests::responses_text_format::responses_text_format_json_object ... FAILED
test openai::tests::responses_text_format::responses_text_format_invalid_rejected ... FAILED
test openai::tests::responses_text_format::responses_text_format_json_schema ... FAILED
expected JsonSchema, got None
test result: FAILED. 1 passed; 3 failed; 0 ignored; 0 measured; 3247 filtered out

After the fix:

test openai::tests::responses_text_format::responses_text_format_json_object ... ok
test openai::tests::responses_text_format::responses_text_format_unconstrained ... ok
test openai::tests::responses_text_format::responses_text_format_json_schema ... ok
test openai::tests::responses_text_format::responses_text_format_invalid_rejected ... ok
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 3247 filtered out

Full ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark: ok. 3244 passed; 0 failed; 14 ignored (on main after #63, rebased).

  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests
  • bash scripts/check-license-headers.sh (4266 valid, 0 invalid)
  • typos
  • Tested against a real model / hardware: not run. GPU hosts are reserved for HY4 work, and a server with no model loaded returns 503 model_not_loaded before lowering runs, so it cannot show this change.
  • Added tests

Try it (against a served model):

curl localhost:8080/v1/responses -H 'Content-Type: application/json' -d '{"model":"YOUR_MODEL","input":"Return an object with answer equal to 42.","text":{"format":{"type":"json_schema","name":"answer","schema":{"type":"object","properties":{"answer":{"type":"integer"}},"required":["answer"],"additionalProperties":false},"strict":true}}}'

Notes for reviewers

Untested: whether a live model's output actually conforms to the schema. Both the streaming and the blocking Responses paths turn the lowered request into the existing chat request, which derives the grammar from response_format. That was checked by reading the code, not by running it.

CLA


Software Factory opened this PR for Robert
Implemented in session Enforce text.format schemas in Responses API
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration
devin-ai-integration Bot changed the base branch from devin/1795385477-fix-spark-test-build to main November 22, 2026 22:24
maplepaladin73 and others added 2 commits November 22, 2026 22:24
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795385672-responses-text-format branch from 2db2d89 to 6be1a34 Compare November 22, 2026 22:24
@maplepaladin73
maplepaladin73 merged commit 56d3be5 into main Nov 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant