Skip to content

fix: accept JSON schemas in structured output parser - #1125

Open
Iams4kura wants to merge 1 commit into
ScrapeGraphAI:pre/betafrom
Iams4kura:bugfix/accept-json-schema-parser-20260811t080236z
Open

fix: accept JSON schemas in structured output parser#1125
Iams4kura wants to merge 1 commit into
ScrapeGraphAI:pre/betafrom
Iams4kura:bugfix/accept-json-schema-parser-20260811t080236z

Conversation

@Iams4kura

Copy link
Copy Markdown

Summary

  • Fixes: Passing a supported JSON Schema dictionary into structured-output generation raises TypeError before any model request instead of parsing the returned dictionary.
  • Root cause: get_structured_output_parser documents and types dictionaries as valid schemas but calls the class-only issubclass builtin before dispatching dictionary schemas to _dict_output_parser.

Regression evidence

  • Before: PYTHONDONTWRITEBYTECODE=1 uv run --frozen pytest -o addopts='' -p no:cacheprovider tests/utils/output_parser_test.py::test_structured_output_parser_accepts_json_schema -q exited 1

  • After: PYTHONDONTWRITEBYTECODE=1 uv run --frozen pytest -o addopts='' -p no:cacheprovider tests/utils/output_parser_test.py::test_structured_output_parser_accepts_json_schema -q exited 0

Verification

  • PYTHONDONTWRITEBYTECODE=1 .venv/bin/pytest -o addopts='' -p no:cacheprovider tests/utils/output_parser_test.py -q
  • PYTHONDONTWRITEBYTECODE=1 .venv/bin/pytest -o addopts='' -p no:cacheprovider tests/test_json_scraper_graph.py -q
  • .venv/bin/ruff check scrapegraphai/utils/output_parser.py tests/utils/output_parser_test.py
  • .venv/bin/black --check scrapegraphai/utils/output_parser.py tests/utils/output_parser_test.py
  • .venv/bin/isort --check-only scrapegraphai/utils/output_parser.py tests/utils/output_parser_test.py
  • uv build --no-sources
  • offline ChatOpenAI.with_structured_output JSON Schema contract check

Scope

  • 2 files changed, +18 / -1 lines

Local full-suite note

I also attempted the repository CI selection, uv run pytest tests/ -m "unit or not integration". It reached 95% with unrelated live-provider, browser, network, and existing assertion failures, then was interrupted when an external proxy request stalled. The deterministic affected suites listed above pass.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working tests Improvements or additions to test labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files. tests Improvements or additions to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant