diff --git a/libs/core/langchain_core/utils/json_schema.py b/libs/core/langchain_core/utils/json_schema.py index 9628f9e521b..95313b3f954 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 = schema for 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.py index 3b0c7b4fe51..6f0a00fd99d 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