Skip to content

Commit b944390

Browse files
cosminachoclaude
andcommitted
Nit: tighten the model_details field_validator
Keep field_validator (default_factory with data arg breaks LangChain's internal zero-arg call at langchain_core/utils/pydantic.py). Rename the method to _resolve and inline the fetch so the validator body is one short try/except block. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a2c7c6e commit b944390

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

  • packages/uipath_langchain_client/src/uipath_langchain_client

packages/uipath_langchain_client/src/uipath_langchain_client/base_client.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,32 +119,27 @@ class UiPathBaseLLMClient(BaseModel, ABC):
119119
default=None,
120120
description="Per-model capability flags sourced from the discovery endpoint "
121121
"(e.g. {'shouldSkipTemperature': True}). The factory forwards it; when absent, "
122-
"the field validator below eagerly resolves it from client_settings.",
122+
"the field validator below resolves it eagerly from client_settings.",
123123
)
124124

125125
@field_validator("model_details", mode="after")
126126
@classmethod
127-
def _resolve_model_details(
128-
cls, value: dict[str, Any] | None, info: ValidationInfo
129-
) -> dict[str, Any]:
130-
# Fields validate in declaration order, so by the time this runs both
131-
# ``client_settings`` and ``model_name`` are already in ``info.data``.
132-
# Eager resolution here keeps direct instantiation and the factory
133-
# path consistent. ``get_available_models`` is class-cached inside
134-
# the settings layer, so at most one discovery HTTP call fires per
135-
# process regardless of how many chat/embedding models are built.
136-
if value is not None:
137-
return value
138-
settings = info.data.get("client_settings")
139-
model_name = info.data.get("model_name")
140-
if settings is None or not model_name:
141-
return {}
127+
def _resolve(cls, v: dict[str, Any] | None, info: ValidationInfo) -> dict[str, Any]:
128+
# Fields validate in declaration order: client_settings and model_name
129+
# are already in info.data. get_available_models is class-cached inside
130+
# the settings layer, so at most one discovery HTTP call per process.
131+
if v is not None:
132+
return v
142133
try:
143-
model_info = settings.get_model_info(
144-
model_name,
145-
byo_connection_id=info.data.get("byo_connection_id"),
134+
return (
135+
info.data["client_settings"]
136+
.get_model_info(
137+
info.data["model_name"],
138+
byo_connection_id=info.data.get("byo_connection_id"),
139+
)
140+
.get("modelDetails")
141+
or {}
146142
)
147-
return model_info.get("modelDetails") or {}
148143
except Exception:
149144
return {}
150145

0 commit comments

Comments
 (0)