Skip to content
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

core[patch]: Fix utils.json_schema.dereference_refs (#24335 KeyError: 400 in JSON schema processing) #24337

Merged
merged 4 commits into from
Jul 19, 2024

Conversation

eunhye1kim
Copy link
Contributor

Description:
This PR fixes a KeyError: 400 that occurs in the JSON schema processing within the reduce_openapi_spec function. The _retrieve_ref function in json_schema.py was modified to handle missing components gracefully by continuing to the next component if the current one is not found. This ensures that the OpenAPI specification is fully interpreted and the agent executes without errors.

Issue:
Fixes issue #24335

Dependencies:
No additional dependencies are required for this change.

Twitter handle:
@lunara_x

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 17, 2024
Copy link

vercel bot commented Jul 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Jul 19, 2024 11:30am

@dosubot dosubot bot added Ɑ: core Related to langchain-core 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Jul 17, 2024
- Modify `_retrieve_ref` function in `json_schema.py` to correctly handle both integer and string components.
- Checks if `component` is a digit and if `int(component)` exists in the schema.
- If `int(component)` does not exist, falls back to using `component` as a string key.
- Ensures the OpenAPI specification is fully interpreted and the agent executes without errors.
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 17, 2024
- Add a new test `test_dereference_refs_string_ref` to ensure that string keys are handled properly in JSON schema references.
- Adjust the `test_dereference_refs_missing_ref` to reflect the new behavior of `_retrieve_ref`.
- Ensure that JSON schema processing can handle string keys without raising unnecessary KeyErrors.
- Modify `_retrieve_ref` function to ensure string keys are handled correctly and not incorrectly converted to integers.
- Adjust test cases to ensure correct behavior for both integer and string keys.
@eyurtsev eyurtsev self-assigned this Jul 18, 2024
Copy link

vercel bot commented Jul 19, 2024

Deployment failed with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

…JSON schema utility

- Deleted logic in `_retrieve_ref` function that handled broken references by returning the original schema.
- Adjusted the test `test_dereference_refs_missing_ref` to expect a `KeyError` for broken references.
@@ -18,8 +18,7 @@ def _retrieve_ref(path: str, schema: dict) -> dict:
elif component.isdigit() and int(component) in out:
out = out[int(component)]
else:
# Returning the original schema or a default value if the key is not found
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was added to ensure that the agent runs even if there is a problem with the swagger provided by an external solution. We decided that it was right to remove these reference errors through preprocessing logic before the user applied swagger to the agent, so in this case, we modified the code so that a ValueError was raised and also restored the test code.

@eyurtsev eyurtsev self-requested a review July 19, 2024 17:29
Copy link
Collaborator

@eyurtsev eyurtsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Jul 19, 2024
@eyurtsev eyurtsev changed the title core: Fix #24335 (KeyError: 400 in JSON schema processing) core[patch]: Fix #24335 (KeyError: 400 in JSON schema processing) Jul 19, 2024
@eyurtsev eyurtsev changed the title core[patch]: Fix #24335 (KeyError: 400 in JSON schema processing) core[patch]: Fix utils.json_schema.dereference_refs (#24335 KeyError: 400 in JSON schema processing) Jul 19, 2024
@eyurtsev eyurtsev merged commit 9aae8ef into langchain-ai:master Jul 19, 2024
97 checks passed
olgamurraft pushed a commit to olgamurraft/langchain that referenced this pull request Aug 16, 2024
… KeyError: 400 in JSON schema processing) (langchain-ai#24337)

Description:
This PR fixes a KeyError: 400 that occurs in the JSON schema processing
within the reduce_openapi_spec function. The _retrieve_ref function in
json_schema.py was modified to handle missing components gracefully by
continuing to the next component if the current one is not found. This
ensures that the OpenAPI specification is fully interpreted and the
agent executes without errors.

Issue:
Fixes issue langchain-ai#24335

Dependencies:
No additional dependencies are required for this change.

Twitter handle:
@lunara_x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core lgtm PR looks good. Use to confirm that a PR is ready for merging. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants