skillfed

pydantic-function-models

Migrating v1 Pydantic ValidatedFunction to v2.

pydantic-function-models v0.1.12 589.7K downloads/30d#5,858 on PyPI6
Permissive license MIT Active released

What it is and what it does

pydantic-function-models lets you wrap any Python function to enforce type validation on its arguments using Pydantic's validation engine. It builds an internal Pydantic model from the function's signature and type hints, then validates incoming arguments (positional or keyword) against that model before execution. The package was created to bridge the gap left by Pydantic v2's removal of ValidatedFunction from v1, offering a direct migration path for code that relied on that feature.

The library is designed for cases where you need to model and validate a function's full signature as a structured entity—distinct from Pydantic's validate_call decorator, which is simpler but less flexible for introspection. It includes safeguards against reserved parameter names that could conflict with internal validation logic, and raises clear Pydantic ValidationError messages when arguments don't match declared types.

Use it for:

  • Migrating Pydantic v1 code that used ValidatedFunction to v2 without rewriting validation logic.
  • Building CLI tools or APIs that need to validate function arguments against strict type contracts before execution.
  • Introspecting and modeling function signatures as Pydantic models for serialization or schema generation.
  • Enforcing type safety in plugin systems or dynamic function dispatch where arguments come from untrusted sources.
  • Creating wrapper layers that log or audit function calls with validated, structured argument data.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Wraps Python functions to validate their arguments against type hints using Pydantic models, providing a migration path from Pydantic v1's deprecated ValidatedFunction.

Yes, if you are migrating from Pydantic v1's ValidatedFunction or need to model and validate function signatures as structured Pydantic models. The package is actively maintained, has no known vulnerabilities, and carries a permissive MIT license. Install friction is minimal. However, if you only need basic argument validation without signature introspection, Pydantic's validate_call decorator may be simpler.

Install

pydantic-function-models on PyPI

pip

pip install pydantic-function-models

uv

uv add pydantic-function-models

poetry

poetry add pydantic-function-models

Installing pydantic-function-models

Before you install

Low friction: pure Python wheel with a single runtime dependency on pydantic. Actively maintained with a recent commit (2026-08-10) and no known vulnerabilities.

License in practice

MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.

Quickstart

from pydantic_function_models import ValidatedFunction

def add(a: int, b: int) -> int:
    return a + b

vf = ValidatedFunction(add)
validated = vf.model.model_validate({"a": 1, "b": 2})
result = add(**validated.model_dump(exclude_unset=True))
print(result)  # 3

Requires Python 3.10 or later; pydantic must be installed as the sole runtime dependency.

Verify before relying

  • Whether ValidatedFunction fully replicates Pydantic v1 behavior or has known gaps for complex signatures.
  • Performance characteristics when validating functions with many parameters or nested type hints.
  • Compatibility with Pydantic's validate_call decorator and how the two approaches differ in practice.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pydantic
Maintenance actively maintained — 120 days since the last release
Last repo commit
First released
Downloads 589,678/month — #5,858 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pydantic_function_models-0.1.12-py3-none-any.whl

Keywords: pydantic, serialization, deserialization, parsing

Development Status :: 3 - AlphaFramework :: PydanticFramework :: Pydantic :: 2Intended Audience :: DevelopersNatural Language :: EnglishProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Libraries

Tags

pydantic function argument validationvalidate function signatures pydanticpydantic v1 validatedfunction migrationfunction parameter type checkingpydantic function wrapperruntime argument validationfunction signature modeling
pydantic-v1-migrationtype-validationfunction-wrapping

More Libraries packages