_create_subset_model_v2() — langchain Function Reference
Architecture documentation for the _create_subset_model_v2() function in pydantic.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9e5cf970_9661_1d7f_abe9_9d3a2271e33c["_create_subset_model_v2()"] 892b1d9f_bb87_0364_19af_71382204e430["pydantic.py"] 9e5cf970_9661_1d7f_abe9_9d3a2271e33c -->|defined in| 892b1d9f_bb87_0364_19af_71382204e430 9e5cf970_9661_1d7f_abe9_9d3a2271e33c["_create_subset_model_v2()"] 9e5cf970_9661_1d7f_abe9_9d3a2271e33c -->|calls| 9e5cf970_9661_1d7f_abe9_9d3a2271e33c b0860ec1_de71_8597_62af_8ca59b0ea27b["_create_subset_model()"] b0860ec1_de71_8597_62af_8ca59b0ea27b -->|calls| 9e5cf970_9661_1d7f_abe9_9d3a2271e33c 9e5cf970_9661_1d7f_abe9_9d3a2271e33c["_create_subset_model_v2()"] 9e5cf970_9661_1d7f_abe9_9d3a2271e33c -->|calls| 9e5cf970_9661_1d7f_abe9_9d3a2271e33c style 9e5cf970_9661_1d7f_abe9_9d3a2271e33c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/pydantic.py lines 231–269
def _create_subset_model_v2(
name: str,
model: type[BaseModel],
field_names: list[str],
*,
descriptions: dict | None = None,
fn_description: str | None = None,
) -> type[BaseModel]:
"""Create a Pydantic model with a subset of the model fields."""
descriptions_ = descriptions or {}
fields = {}
for field_name in field_names:
field = model.model_fields[field_name]
description = descriptions_.get(field_name, field.description)
field_info = FieldInfoV2(description=description, default=field.default)
if field.metadata:
field_info.metadata = field.metadata
fields[field_name] = (field.annotation, field_info)
rtn = cast(
"type[BaseModel]",
_create_model_base( # type: ignore[call-overload]
name, **fields, __config__=ConfigDict(arbitrary_types_allowed=True)
),
)
# TODO(0.3): Determine if there is a more "pydantic" way to preserve annotations.
# This is done to preserve __annotations__ when working with pydantic 2.x
# and using the Annotated type with TypedDict.
# Comment out the following line, to trigger the relevant test case.
selected_annotations = [
(name, annotation)
for name, annotation in model.__annotations__.items()
if name in field_names
]
rtn.__annotations__ = dict(selected_annotations)
rtn.__doc__ = textwrap.dedent(fn_description or model.__doc__ or "")
return rtn
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does _create_subset_model_v2() do?
_create_subset_model_v2() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/pydantic.py.
Where is _create_subset_model_v2() defined?
_create_subset_model_v2() is defined in libs/core/langchain_core/utils/pydantic.py at line 231.
What does _create_subset_model_v2() call?
_create_subset_model_v2() calls 1 function(s): _create_subset_model_v2.
What calls _create_subset_model_v2()?
_create_subset_model_v2() is called by 2 function(s): _create_subset_model, _create_subset_model_v2.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free