ProviderStrategy Class — langchain Architecture
Architecture documentation for the ProviderStrategy class in structured_output.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6e90be30_70b3_e6e9_2090_a66fcbf5f221["ProviderStrategy"] c2936c24_74cd_6911_037b_0f67eebfefee["structured_output.py"] 6e90be30_70b3_e6e9_2090_a66fcbf5f221 -->|defined in| c2936c24_74cd_6911_037b_0f67eebfefee 415d0307_f2f9_0751_30a5_e029e33f197a["__init__()"] 6e90be30_70b3_e6e9_2090_a66fcbf5f221 -->|method| 415d0307_f2f9_0751_30a5_e029e33f197a 0d29750e_a10c_2bb6_92ee_0217de4e6087["to_model_kwargs()"] 6e90be30_70b3_e6e9_2090_a66fcbf5f221 -->|method| 0d29750e_a10c_2bb6_92ee_0217de4e6087
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/structured_output.py lines 261–304
class ProviderStrategy(Generic[SchemaT]):
"""Use the model provider's native structured output method."""
schema: type[SchemaT] | dict[str, Any]
"""Schema for native mode."""
schema_spec: _SchemaSpec[SchemaT]
"""Schema spec for native mode."""
def __init__(
self,
schema: type[SchemaT] | dict[str, Any],
*,
strict: bool | None = None,
) -> None:
"""Initialize `ProviderStrategy` with schema.
Args:
schema: Schema to enforce via the provider's native structured output.
strict: Whether to request strict provider-side schema enforcement.
"""
self.schema = schema
self.schema_spec = _SchemaSpec(schema, strict=strict)
def to_model_kwargs(self) -> dict[str, Any]:
"""Convert to kwargs to bind to a model to force structured output.
Returns:
The kwargs to bind to a model.
"""
# OpenAI:
# - see https://platform.openai.com/docs/guides/structured-outputs
json_schema: dict[str, Any] = {
"name": self.schema_spec.name,
"schema": self.schema_spec.json_schema,
}
if self.schema_spec.strict:
json_schema["strict"] = True
response_format: dict[str, Any] = {
"type": "json_schema",
"json_schema": json_schema,
}
return {"response_format": response_format}
Source
Frequently Asked Questions
What is the ProviderStrategy class?
ProviderStrategy is a class in the langchain codebase, defined in libs/langchain_v1/langchain/agents/structured_output.py.
Where is ProviderStrategy defined?
ProviderStrategy is defined in libs/langchain_v1/langchain/agents/structured_output.py at line 261.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free