MCPcopy
hub / github.com/langchain-ai/langchain / config_schema

Method config_schema

libs/core/langchain_core/runnables/base.py:347–389  ·  view source on GitHub ↗

The type of config this runnable accepts specified as a pydantic model. To mark a field as configurable, see the `configurable_fields` and `configurable_alternatives` methods. Args: include: A list of fields to include in the config schema. Returns:

(
        self, *, include: Optional[Sequence[str]] = None
    )

Source from the content-addressed store, hash-verified

345 return []
346
347 def config_schema(
348 self, *, include: Optional[Sequence[str]] = None
349 ) -> Type[BaseModel]:
350 """The type of config this runnable accepts specified as a pydantic model.
351
352 To mark a field as configurable, see the `configurable_fields`
353 and `configurable_alternatives` methods.
354
355 Args:
356 include: A list of fields to include in the config schema.
357
358 Returns:
359 A pydantic model that can be used to validate config.
360 """
361
362 include = include or []
363 config_specs = self.config_specs
364 configurable = (
365 create_model( # type: ignore[call-overload]
366 "Configurable",
367 **{
368 spec.id: (
369 spec.annotation,
370 Field(
371 spec.default, title=spec.name, description=spec.description
372 ),
373 )
374 for spec in config_specs
375 },
376 )
377 if config_specs
378 else None
379 )
380
381 return create_model( # type: ignore[call-overload]
382 self.get_name("Config"),
383 **({"configurable": (configurable, None)} if configurable else {}),
384 **{
385 field_name: (field_type, None)
386 for field_name, field_type in RunnableConfig.__annotations__.items()
387 if field_name in [i for i in include if i != "configurable"]
388 },
389 )
390
391 def get_graph(self, config: Optional[RunnableConfig] = None) -> Graph:
392 """Return a graph representation of this runnable."""

Callers 4

test_schemasFunction · 0.80
test_configurable_fieldsFunction · 0.80

Calls 2

get_nameMethod · 0.95
create_modelFunction · 0.90

Tested by 4

test_schemasFunction · 0.64
test_configurable_fieldsFunction · 0.64