Skip to content

fix(synthesis): Strategy 0 in _parse_response returns prematurely on single JSON objects (#94)#175

Merged
himanshu231204 merged 3 commits into
mainfrom
fix/synthesis-parse-response-premature-return
Jul 17, 2026
Merged

fix(synthesis): Strategy 0 in _parse_response returns prematurely on single JSON objects (#94)#175
himanshu231204 merged 3 commits into
mainfrom
fix/synthesis-parse-response-premature-return

Conversation

@himanshu231204

Copy link
Copy Markdown
Member

Description

Fixes a bug in both QuestionGenerator and AdversarialTestCaseGenerator where Strategy 0 in _parse_response would parse a single JSON object (non-array LLM response), create ONE test case, and return immediately — instead of continuing to other strategies to find more questions.

Root cause: When the LLM returns a single JSON object like {"question": "...", "answer": "..."} instead of a JSON array, Strategy 0 would successfully parse it but then return test_cases prematurely, skipping Strategies 1-4 that could extract additional questions from the same response.

Fix applied to both files:

  1. Removed the premature return in Strategy 0 — now it adds the test case and continues to other strategies
  2. Added deduplication logic via seen_questions set and _add_test_case helper to prevent duplicates when multiple strategies find the same question

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Related Issues

Closes #94

How Has This Been Tested?

  • Unit tests pass (uv run pytest tests/unit/test_synthesis/ -v)
  • Linter passes (uv run ruff check .)
  • Type checker passes (uv run mypy openagent_eval/)
  • Manual testing performed:
    • Single JSON object response → returns 1 question (no error, no premature return)
    • Multiple separate JSON objects → returns all questions (no duplicates)
    • Proper JSON array → returns all questions (works as before)

Checklist

  • My code follows the project's coding standards
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Additional Notes

All 69 synthesis tests pass. The fix is minimal and focused — only the _parse_response methods in question_gen.py and adversarial.py were modified.

Both QuestionGenerator and AdversarialTestCaseGenerator had a bug in their
_parse_response methods where Strategy 0 (single JSON object parsing) would
return immediately after finding one question, instead of continuing to other
strategies to find more questions.

Changes:
- Removed premature 
eturn test_cases in Strategy 0 for both files
- Added deduplication via seen_questions set and _add_test_case helper
- All parsing strategies now use the helper to avoid duplicate questions

Fixes issue #94 where requesting N questions but receiving a single JSON object
would only return 1 question instead of attempting other parsing strategies.
@himanshu231204 himanshu231204 self-assigned this Jul 17, 2026
@himanshu231204
himanshu231204 merged commit 86e1ae6 into main Jul 17, 2026
10 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Congratulations @himanshu231204!

Your pull request has been successfully merged into main. 🚀

Thank you for contributing to OpenAgentHQ and helping improve the project.

We truly appreciate your contribution and hope to see you back with more amazing PRs!

Happy Open Sourcing! ❤️

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.

synthesis(question_gen/adversarial): Strategy 0 in _parse_response returns prematurely on single JSON objects

1 participant