Skip to content

fix: handle single-quote JSON and non-array responses in synthesis parser#36

Open
himanshu231204 wants to merge 1 commit into
mainfrom
fix/single-quote-json-handling
Open

fix: handle single-quote JSON and non-array responses in synthesis parser#36
himanshu231204 wants to merge 1 commit into
mainfrom
fix/single-quote-json-handling

Conversation

@himanshu231204

Copy link
Copy Markdown
Contributor

Summary

Fixes 3 failing synthesis tests by improving JSON parsing resilience in both QuestionGenerator and AdversarialTestCaseGenerator.

Changes

1. Smart single-quote normalization (question_gen.py, adversarial.py)

When the LLM outputs Python-style dict formatting like {'question': 'What is X?', 'answer': '...'}, the parser now detects single-quoted keys via the regex \{\s*'[^']*'\s*: and normalizes them to valid JSON double quotes. This avoids corrupting apostrophes in valid double-quoted JSON (e.g. "company's" remains intact).

2. Single JSON object handling (question_gen.py, adversarial.py)

Added Strategy 0 to parse standalone {...} JSON objects (non-array responses) as valid single-element response arrays.

3. Normalized text in fallback strategies (question_gen.py, adversarial.py)

Redirected regex-based fallback strategies (2, 3, 4) to use the normalized text variable instead of the raw response, so they also benefit from single-quote normalization.

4. Fixed stale test assertion (test_question_gen.py)

Updated test_generate_non_array_response error message matcher from "Expected JSON array" (v0.4.3 refactor artifact) to "Failed to parse".

Testing

  • All 66 synthesis tests pass (previously 3 failed)
  • Full test suite: 876 passed, 3 skipped (pre-existing)

…rser

Add smart single-quote normalization that only triggers on Python-style dict formatting, avoiding corruption of apostrophes in valid JSON.

Add Strategy 0 to parse single JSON objects as valid single-element responses. Redirect regex-based fallback strategies to use normalized text.

Fix stale test: test_generate_non_array_response expected old error message Expected JSON array instead of current Failed to parse.
)
)
return test_cases
except (json.JSONDecodeError, ValueError):
)
)
return test_cases
except (json.JSONDecodeError, ValueError):
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