The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Update _retrieve_ref inside json_schema.py to include an isdigit() check (#14745)
Paresh Chiramel9be08a1956fb
diff --git a/libs/core/langchain_core/utils/json_schema.py b/libs/core/langchain_core/utils/json_schema.pyindex 9628f9e521..95313b3f95 100644--- a/libs/core/langchain_core/utils/json_schema.py+++ b/libs/core/langchain_core/utils/json_schema.py@@ -13,7 +13,10 @@ def _retrieve_ref(path: str, schema: dict) -> dict:)out = schemafor component in components[1:]:- out = out[component]+ if component.isdigit():+ out = out[int(component)]+ else:+ out = out[component]return deepcopy(out)diff --git a/libs/core/tests/unit_tests/utils/test_json_schema.py b/libs/core/tests/unit_tests/utils/test_json_schema.pyindex 3b0c7b4fe5..6f0a00fd99 100644--- a/libs/core/tests/unit_tests/utils/test_json_schema.py+++ b/libs/core/tests/unit_tests/utils/test_json_schema.py@@ -149,3 +149,35 @@ def test_dereference_refs_remote_ref() -> None:}with pytest.raises(ValueError):dereference_refs(schema)+++def test_dereference_refs_integer_ref() -> None:+ schema = {+ "type": "object",+ "properties": {+ "error_400": {"$ref": "#/$defs/400"},+ },+ "$defs": {+ 400: {+ "type": "object",+ "properties": {"description": "Bad Request"},+ },+ },+ }+ expected = {+ "type": "object",+ "properties": {+ "error_400": {+ "type": "object",+ "properties": {"description": "Bad Request"},+ },+ },+ "$defs": {+ 400: {+ "type": "object",+ "properties": {"description": "Bad Request"},+ },+ },+ }+ actual = dereference_refs(schema)+ assert actual == expected