json_schema.py — langchain Source File
Architecture documentation for json_schema.py, a python file in the langchain codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR e949a363_87d5_a34f_ea76_18a6a6268498["json_schema.py"] e874d8a4_cef0_9d0b_d1ee_84999c07cc2c["copy"] e949a363_87d5_a34f_ea76_18a6a6268498 --> e874d8a4_cef0_9d0b_d1ee_84999c07cc2c 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] e949a363_87d5_a34f_ea76_18a6a6268498 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] e949a363_87d5_a34f_ea76_18a6a6268498 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 style e949a363_87d5_a34f_ea76_18a6a6268498 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Utilities for JSON Schema."""
from __future__ import annotations
from copy import deepcopy
from typing import TYPE_CHECKING, Any, cast
if TYPE_CHECKING:
from collections.abc import Sequence
def _retrieve_ref(path: str, schema: dict) -> list | dict:
"""Retrieve a referenced object from a JSON schema using a path.
Resolves JSON schema references (e.g., `'#/definitions/MyType'`) by traversing the
schema structure.
Args:
path: Reference path starting with `'#'` (e.g., `'#/definitions/MyType'`).
schema: The JSON schema dictionary to search in.
Returns:
A deep copy of the referenced object (dict or list).
Raises:
ValueError: If the path does not start with `'#'`.
KeyError: If the reference path is not found in the schema.
"""
components = path.split("/")
if components[0] != "#":
msg = (
"ref paths are expected to be URI fragments, meaning they should start "
"with #."
)
raise ValueError(msg)
out: list | dict = schema
for component in components[1:]:
if component in out:
if isinstance(out, list):
msg = f"Reference '{path}' not found."
raise KeyError(msg)
out = out[component]
elif component.isdigit():
index = int(component)
if (isinstance(out, list) and 0 <= index < len(out)) or (
isinstance(out, dict) and index in out
):
out = out[index]
else:
msg = f"Reference '{path}' not found."
raise KeyError(msg)
else:
msg = f"Reference '{path}' not found."
raise KeyError(msg)
return deepcopy(out)
def _process_dict_properties(
properties: dict[str, Any],
full_schema: dict[str, Any],
// ... (214 more lines)
Domain
Subdomains
Functions
Dependencies
- collections.abc
- copy
- typing
Source
Frequently Asked Questions
What does json_schema.py do?
json_schema.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in json_schema.py?
json_schema.py defines 5 function(s): _dereference_refs_helper, _process_dict_properties, _retrieve_ref, collections, dereference_refs.
What does json_schema.py depend on?
json_schema.py imports 3 module(s): collections.abc, copy, typing.
Where is json_schema.py in the architecture?
json_schema.py is located at libs/core/langchain_core/utils/json_schema.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/core/langchain_core/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free