Skip to content

[codex] Harden JSON array extraction#103

Merged
Yif-Yang merged 2 commits into
microsoft:mainfrom
zixuanguo786-ctrl:codex/robust-json-array-extraction
Jul 14, 2026
Merged

[codex] Harden JSON array extraction#103
Yif-Yang merged 2 commits into
microsoft:mainfrom
zixuanguo786-ctrl:codex/robust-json-array-extraction

Conversation

@zixuanguo786-ctrl

Copy link
Copy Markdown
Contributor

Summary

  • Add a string/object-aware scanner for top-level JSON array responses.
  • Ignore bracketed prose and arrays nested inside JSON objects.
  • Keep multiple valid top-level arrays ambiguous instead of guessing.

Test plan

  • uv run --with pytest pytest tests/test_json_utils.py -q
  • uv run --with ruff ruff check skillopt/utils/json_utils.py tests/test_json_utils.py

LLM responses can include bracketed prose before the actual JSON array. The old greedy regex spanned from the first '[' to the last ']', causing valid single-array answers to be dropped and making multiple arrays indistinguishable.

Constraint: Keep object extraction behavior unchanged.

Rejected: Return first parseable array | silently guesses when a response has multiple valid arrays.

Confidence: high

Scope-risk: narrow

Reversibility: clean

Directive: Keep array extraction conservative when more than one valid top-level array is present.

Tested: uv run --with pytest pytest tests/test_json_utils.py -q

Tested: uv run --with ruff ruff check skillopt/utils/json_utils.py tests/test_json_utils.py

Not-tested: Full benchmark rollouts.
@Yif-Yang

Copy link
Copy Markdown
Contributor

Hi @zixuanguo786-ctrl — the balanced/ambiguity-aware array extraction is a good improvement. Testing locally I did hit one edge case: an unmatched { before a later valid array (e.g. Explanation uses {placeholder, final answer [1, 2]) now returns None where it previously returned [1, 2], because brace_depth stays > 0. Worth guarding before merge. Is this ready, or still WIP?

@zixuanguo786-ctrl

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@zixuanguo786-ctrl
zixuanguo786-ctrl marked this pull request as ready for review July 14, 2026 02:04
@Yif-Yang
Yif-Yang merged commit 7191f1c into microsoft:main Jul 14, 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.

2 participants