[PR #762] [CLOSED] serve: extract JSON from prose and code fences #2816

Closed
opened 2026-11-04 02:03:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/762
Author: @cipgysmo
Created: 10/4/2026
Status: ❌ Closed

Base: main ← Head: fix/structured-json-extraction


📝 Commits (1)

  • 2cee7b2 serve: extract JSON from prose and code fences

📊 Changes

1 file changed (+38 additions, -1 deletions)

View changed files

📝 serve/structured.py (+38 -1)

📄 Description

In tool-heavy runs, the model often returns valid JSON after a short explanation or inside a Markdown code fence. validated_json() previously passed the whole assistant message to json.loads(), so those otherwise-correct structured responses failed.

This adds a small _extract_json() helper that:

  • strips a leading Markdown code fence,
  • finds the first balanced top-level {...} object,
  • leaves non-object text unchanged so existing error messages remain useful.

This was one of the highest-value fixes in our local dual-GPU tool-eval runs: it made structured output tolerant of normal model prose without changing the benchmark or forcing extra JSON-only prompts.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/762 **Author:** [@cipgysmo](https://github.com/cipgysmo) **Created:** 10/4/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/structured-json-extraction` --- ### 📝 Commits (1) - [`2cee7b2`](https://github.com/Niko1221/Strata/commit/2cee7b2109066ece63c4a6c8bad6db83572ed893) serve: extract JSON from prose and code fences ### 📊 Changes **1 file changed** (+38 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/structured.py` (+38 -1) </details> ### 📄 Description In tool-heavy runs, the model often returns valid JSON after a short explanation or inside a Markdown code fence. `validated_json()` previously passed the whole assistant message to `json.loads()`, so those otherwise-correct structured responses failed. This adds a small `_extract_json()` helper that: - strips a leading Markdown code fence, - finds the first balanced top-level `{...}` object, - leaves non-object text unchanged so existing error messages remain useful. This was one of the highest-value fixes in our local dual-GPU tool-eval runs: it made structured output tolerant of normal model prose without changing the benchmark or forcing extra JSON-only prompts. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:03:19 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2816
No description provided.