Skip to content

fix(converter): fall back on invalid JSON-like partial matches#5461

Open
ibrahim1023 wants to merge 2 commits intocrewAIInc:mainfrom
ibrahim1023:fix-5460-partial-json-fallback
Open

fix(converter): fall back on invalid JSON-like partial matches#5461
ibrahim1023 wants to merge 2 commits intocrewAIInc:mainfrom
ibrahim1023:fix-5460-partial-json-fallback

Conversation

@ibrahim1023
Copy link
Copy Markdown

@ibrahim1023 ibrahim1023 commented Apr 15, 2026

Summary

Fixes issue #5460.

output_pydantic could fail when the model output contained brace-delimited text that looked like JSON but was actually plain string content, such as a GraphQL schema. In that case, partial JSON extraction matched the {...} block, Pydantic validation failed, and the error was raised instead of falling back to the normal conversion path.

This PR fixes that fallback behavior and adds regression coverage for the reported case.

Changes

  • treat invalid JSON-like partial matches as a fallback case in handle_partial_json(...)
  • add a regression test for GraphQL schema text containing braces

Rationale

The existing partial JSON logic is meant to recover valid JSON embedded in a larger response. The bug was that a false-positive match was handled as fatal, even though it should have been treated the same way as any other unsuccessful partial extraction attempt.

With this change, valid partial JSON still parses as before, while non-JSON brace content now falls through to the existing instruction-based converter path.

Testing

  • ./.venv/bin/python -m pytest lib/crewai/tests/utilities/test_converter.py -k "invalid_json_like_partial or partial_json" -q

Notes

  • uv.lock is intentionally not included because it is unrelated to this fix
  • running the full test_converter.py file in this environment still hits an unrelated pre-existing LiteLLM dependency issue

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