-
Notifications
You must be signed in to change notification settings - Fork 18.6k
fix(core): raise OutputParserException
for non-dict JSON outputs
#32236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(core): raise OutputParserException
for non-dict JSON outputs
#32236
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
CodSpeed WallTime Performance ReportMerging #32236 will not alter performanceComparing
|
CodSpeed Instrumentation Performance ReportMerging #32236 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves error handling in the JSON output parser by adding explicit validation to ensure JSON parsing results in a dictionary object. Previously, the parser would only check for valid JSON syntax but wouldn't validate the type, potentially causing issues when non-dict JSON (like numbers or strings) was parsed.
- Adds type validation to raise
OutputParserException
when parsed JSON is not a dictionary - Includes a descriptive error message showing the actual type and content received
- Adds comprehensive test coverage for the new validation behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
libs/core/langchain_core/utils/json.py | Adds type validation after JSON parsing to ensure result is a dict |
libs/core/tests/unit_tests/output_parsers/test_json.py | Adds test case and imports for the new validation behavior |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
@Yash-Tobre please resolve CI failures 🙏 |
On it! |
OutputParserException
for non-dict JSON outputs
@Yash-Tobre looks like tests are still failing |
Deployment failed with the following error:
|
There are a few little formatting issues- figuring them out. Hopefully should be done within the next 24 hours. |
@Yash-Tobre Have you tried running |
Yes - on my end, it works perfectly fine; with all checks passed. Trying to figure it out. |
I think it is resolved now - thank you for your patience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this here?
@@ -5,12 +5,17 @@ | |||
import pytest | |||
from pydantic import BaseModel, Field | |||
|
|||
# Removed incorrect import of parse_and_check_json_markdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this comment here?
@@ -110,7 +111,8 @@ async def consumer() -> AsyncIterator[dict]: | |||
# To verify that the producer and consumer are running in parallel, we | |||
# expect the delta_time to be smaller than the sleep delay in the producer | |||
# * # of items = 30 ms | |||
assert math.isclose(delta_time, 0, abs_tol=0.020) is True, ( | |||
tolerance = 0.03 if sys.version_info[:2] in [(3, 9), (3, 11)] else 0.02 | |||
assert math.isclose(delta_time, 0, abs_tol=tolerance), ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated to the PR, no need to fix.
Description:
Raise a more descriptive OutputParserException when JSON parsing results in a non-dict type. This improves debugging and aligns behavior with expectations when using expected_keys.
Issue:
Fixes #32233
Twitter handle:
@yashvtobre
Testing:
Notes: