fix: handle single-quote JSON and non-array responses in synthesis parser#36
Open
himanshu231204 wants to merge 1 commit into
Open
fix: handle single-quote JSON and non-array responses in synthesis parser#36himanshu231204 wants to merge 1 commit into
himanshu231204 wants to merge 1 commit into
Conversation
…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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 3 failing synthesis tests by improving JSON parsing resilience in both
QuestionGeneratorandAdversarialTestCaseGenerator.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
textvariable 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_responseerror message matcher from"Expected JSON array"(v0.4.3 refactor artifact) to"Failed to parse".Testing