Issues / #2467
#2467 [Bug]: json_object silently discards elements from array-root output
open · @bettercallcaleb · 1 comments · View on GitHub
Description
### What happened
With `response_format: {"type":"json_object"}`, an array-root model response can be accepted as a successful JSON object. `_extract_json()` selects the first balanced `{...}` inside the array and drops the remaining elements.
Reproduced on unmodified `main` (`296b59d`):
```bash
python3 - <<'PY'
from serve.structured import _ObjectOnly, validated_json
raw = '[{"answer":1},{"answer":2}]'
print(validated_json(raw, _ObjectOnly(), "stop"))
PY
```
Actual: `{"answer":1}`. The mock HTTP endpoint also returned 200 with that truncated object.
Expected: reject an array-root response with `structured_output_failed` (HTTP 502 for non-streaming requests), not silently reinterpret it as an object. Existing support for an object inside prose or a Markdown code fence (#762) should remain intact.
### Strata version, GPU, OS
`main` at `296b59d` · Ubuntu 24.04 LTS · Python 3.12 · GPU not used (parser-only and MockEngine HTTP reproduction).
Related on this site
Quick links to related pages.