Skip to main content

call_schema

Returns a schema that matches an arguments schema, then calls a function, e.g.:

```py
from pydantic_core import SchemaValidator, core_schema

param_a = core_schema.arguments_parameter(
name='a', schema=core_schema.str_schema(), mode='positional_only'
)
param_b = core_schema.arguments_parameter(
name='b', schema=core_schema.bool_schema(), mode='positional_only'
)
args_schema = core_schema.arguments_schema([param_a, param_b])

schema = core_schema.call_schema(
arguments=args_schema,
function=lambda a, b: a + str(not b),
return_schema=core_schema.str_schema(),
)
v = SchemaValidator(schema)
assert v.validate_python((('hello', True))) == 'helloFalse'
```
def call_schema(
arguments: CoreSchema,
function: Callable[..., Any],
function_name: str | None = None,
return_schema: CoreSchema | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None
) - > CallSchema

Returns a schema that matches an arguments schema, then calls a function.

Parameters

NameTypeDescription
argumentsCoreSchemaThe schema used to validate and parse the arguments before they are passed to the function.
functionCallable[..., Any]The callable object to be executed with the validated arguments.
function_name`strNone` = None
return_schema`CoreSchemaNone` = None
ref`strNone` = None
metadata`dict[str, Any]None` = None
serialization`SerSchemaNone` = None

Returns

TypeDescription
CallSchemaA dictionary-based schema configuration of type 'call' used by pydantic-core to validate arguments and execute the associated function.