Skip to content

Studio: fix structured columns in Data Recipes on non-GGUF models - #11049

Merged
Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:fix-recipe-structured-non-gguf
Sep 16, 2026
Merged

Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:fix-recipe-structured-non-gguf

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

A recipe with a structured column failed on every row when the Chat model was not a GGUF, for example a safetensors model. The run ended with "Dataset is empty" and the good text columns were lost too. This started after #9262.

Recipes now only ask for strict JSON output when the model runs on llama.cpp (GGUF). Other models go back to asking for JSON in the prompt, which is how it worked before #9262. #10611 made the same kind of fix for Deep Research.

With a 3 row recipe on Qwen3-0.6B (safetensors), main failed with "Dataset is empty" and this change completes with values like {"name":"Riverside","score":8}. The GGUF model and a recipe without a structured column still work. Added a unit test that fails on main.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T07:35:42.379858Z d020671 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + reproduction evidence

Pinned review: 0b1a63fd5eae4d9029d2f43f6002aa238782bac6 — no blocking code findings. /v1/chat/completions refuses any constraining response_format when llama_backend.is_loaded is false ("response_format needs the llama.cpp grammar engine"), and the recipe now gates the injection on that same check, so the two cannot disagree.

Real Studio run (Modal L4, Chromium 1440×900). Same 3-record test run, pasted through Recipe Studio's import, with an llm-text column and an llm-structured column ({name: string, score: integer}) on safetensors unsloth/Qwen3-0.6B:

  • Merge base 12865908: job error — "🛑 Dataset is empty — all records were dropped…", 0 rows. The Studio log shows the three text calls return 200 and the three structured calls return 400. The UI shows Preview failed and Execution failed.
  • PR head 0b1a63f: job completed, 3 rows, 3/3 valid ratings, e.g. {"name":"Cozy Coffee Haven","score":8}, {"name":"Creative Coffee Haven","score":9}. The UI shows Preview generated (3 rows).
  • GGUF control on PR head (unsloth/Qwen3-0.6B-GGUF Q4_K_M, grammar path): completed, 3 rows, 3/3 valid ratings.

PR 11049 before/after

GitHub Actions A/B (fresh main 56d19467 + PR; the two branches differ only in studio/backend/routes/data_recipe/jobs.py):

  • Fix reverted — expected-failing run: test_non_gguf_model_keeps_prompt_level_json FAILED — {'rating': 'local_model__rating_structured'} != {'rating': 'local_model'}, i.e. the non-GGUF structured column was still repointed at a llama.cpp-only response_format clone. The GGUF test passes.
  • PR head — passing run: 2 passed. Setup and the 9 dependent recipe tests (test_job_accounts, test_desktop_auth) pass on both sides.

Full CI on a fork (fresh main 56d19467 + PR): all 15/15 workflows green, including Backend CI, Core, Kaggle T4 GPU, Mac UI/API/Update/Inference, Windows UI/API/GGUF, GGUF, Wheel and Lint (Backend CI, Mac, Windows UI).

Conclusion: the structured-column failure on non-GGUF models and its fix are verified end to end, and the GGUF grammar path is unchanged.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits studio/backend/routes/data_recipe/jobs.py where the structured response_format is injected even when the loaded model is not served by llama.cpp, which drops the whole recipe output on safetensors models. Will get this reviewed.

@Lyxot Lyxot self-assigned this Sep 16, 2026
…oute's refusal

Follow-up to the recipe structured-column fix on the same branch. The gate was threaded out of _loaded_local_model_identity and _ensure_selected_local_model_loaded as a fourth tuple member and a return value, which left an "ensure" helper reporting the backend kind and a four-member tuple whose two booleans sit at opposite ends. _inject_local_providers is synchronous with no await between the model-loaded check and the injection, and get_llama_cpp_backend is a module-global accessor, so reading is_loaded again at the injection site cannot disagree with the first read. Both original signatures are restored, which also makes the existing _ensure_selected_local_model_loaded stub in test_job_accounts.py correct again.

The comment above the gate now says why a non-GGUF backend is excluded and what it falls back to, rather than only describing the injection the called function already documents.

Adds a test asserting that the payload the GGUF path injects is exactly what the local /v1 route refuses without llama.cpp, so teaching the safetensors/MLX backend guided decoding fails here instead of leaving recipes asking it for prompt-level JSON. The non-GGUF test now compares whole columns rather than aliases, since output_format is what that prompt-level schema is built from, and the schema constant is deep-copied into the recipe so it stays a pristine expectation against an injector that forwards it by reference.
@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Pushed d020671a07. The gate itself is unchanged in behavior — this only tightens how it is read and what proves it.

Production. The gate was threaded out of _loaded_local_model_identity as a fourth tuple member and out of _ensure_selected_local_model_loaded as a return value, which left an "ensure" helper reporting the backend kind and a four-member tuple whose two booleans sit at opposite ends. It is now a two-line _local_chat_serves_gguf() read at the injection site, and both original signatures are restored — which also makes the existing _ensure_selected_local_model_loaded stub in test_job_accounts.py correct again. This is safe because _inject_local_providers is synchronous with no await between the model-loaded check and the injection, and get_llama_cpp_backend is a plain module-global accessor, so the second read of is_loaded cannot disagree with the first. Net production diff is now +9/-3.

The comment above the gate now says why a non-GGUF backend is excluded and what it falls back to, instead of only restating the injection the called function already documents.

Tests. Added one: the payload the GGUF path injects is exactly what the local /v1 route refuses without llama.cpp. Nothing previously tied the gate to the refusal that motivates it, so teaching the safetensors/MLX backend guided decoding would have left recipes quietly asking it for prompt-level JSON; now it fails here instead.

The non-GGUF test compares whole columns rather than aliases, since output_format is what that prompt-level schema instruction is built from and stripping it would have passed the old assertions. The schema constant is deep-copied into the recipe so it stays a pristine expectation against an injector that forwards it by reference.

Validation. Every added assertion was mutation-checked in both directions: forcing the gate on fails only the non-GGUF test, forcing it off fails the GGUF test and the new route test, and making _response_format_constrains_decoding return False fails only the route test. 238 tests pass across test_data_recipe_structured_response_format, test_job_accounts, test_desktop_auth, test_research_json_fallback and test_sf_client_tools_passthrough. The change was also applied to current main, where routes/inference.py has moved ~400 lines since this branch's base, and passes there too.

One note for reviewers on the approach rather than the code: #10611 solved the same problem for Deep Research by sending response_format, catching the 400 and retrying without it, whereas this decides up front. Preflight avoids a wasted round-trip on every structured row, which matters at recipe scale, but it is point-in-time — a GGUF to safetensors swap mid-run leaves later rows refused. The model-identity check directly above carries the same documented TOCTOU, so this is consistent with its neighbour, but it is a deliberate difference worth naming.

@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d020671a07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: d020671a07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Lyxot Lyxot 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.

Approving. Real bug, right fix, and the gate mirrors the condition /v1 itself dispatches on (using_gguf = llama_backend.is_loaded), so the two cannot drift apart.

Re-verified against today's main (f70af706b1): merges clean, the merged result is exactly the two files, and the refusal the gate exists to avoid is still there. Tests pass on the merged tree, and the gate mutation-checks on it — forcing the gate on fails the non-GGUF test and nothing else. A staging CI run of the rebased change was green on every job covering this code, including the backend shard that runs the new test.

The fallback is not a hope: data_designer's StructuredResponseRecipe always emits the JSON-fence instruction and the schema in <response_schema> tags regardless of response_format, llm-judge columns already run that way on every backend including GGUF, and the default max_conversation_restarts=5 retries a parse miss.

Disclosure: I pushed the follow-up commit d020671a07 to this branch, so this is not a fully independent approval of every line. The original fix is @NilayYadav's.

Note for whoever merges: the red jobs are not from this PR. test_no_test_file_spawns_powershell_directly fails on a clean main today, and the Core zoo failures are in unsloth-zoo at its pinned commit, a repository this change does not touch. Both preset-sheet and multi-account failures seen earlier have since been fixed on main.

@Lyxot
Lyxot merged commit 9a127b6 into unslothai:main Sep 16, 2026
38 of 41 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…slothai#11049)

* Studio: only send grammar response_format for recipe structured columns on GGUF models

* Studio: read the GGUF gate at the injection site, and tie it to the route's refusal

Follow-up to the recipe structured-column fix on the same branch. The gate was threaded out of _loaded_local_model_identity and _ensure_selected_local_model_loaded as a fourth tuple member and a return value, which left an "ensure" helper reporting the backend kind and a four-member tuple whose two booleans sit at opposite ends. _inject_local_providers is synchronous with no await between the model-loaded check and the injection, and get_llama_cpp_backend is a module-global accessor, so reading is_loaded again at the injection site cannot disagree with the first read. Both original signatures are restored, which also makes the existing _ensure_selected_local_model_loaded stub in test_job_accounts.py correct again.

The comment above the gate now says why a non-GGUF backend is excluded and what it falls back to, rather than only describing the injection the called function already documents.

Adds a test asserting that the payload the GGUF path injects is exactly what the local /v1 route refuses without llama.cpp, so teaching the safetensors/MLX backend guided decoding fails here instead of leaving recipes asking it for prompt-level JSON. The non-GGUF test now compares whole columns rather than aliases, since output_format is what that prompt-level schema is built from, and the schema constant is deep-copied into the recipe so it stays a pristine expectation against an injector that forwards it by reference.

---------

Co-authored-by: Lyxot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants