{"id":6790,"library":"pydantic-function-models","title":"pydantic-function-models","description":"A library designed to model Python function signatures using Pydantic, offering a modern alternative to the now-deprecated `ValidatedFunction` from Pydantic v1. It facilitates the validation of function arguments based on type hints, bridging compatibility gaps between Pydantic v1 and v2. The library is currently at version 0.1.11, with updates reflecting ongoing maintenance.","status":"active","version":"0.1.11","language":"en","source_language":"en","source_url":"https://github.com/lmmx/pydantic-function-models","tags":["pydantic","validation","function signature","pydantic v2","pydantic v1 migration","type hints"],"install":[{"cmd":"pip install pydantic-function-models","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core dependency for function signature modeling and validation (supports both v1 and v2 due to library's bridging purpose).","package":"pydantic"}],"imports":[{"note":"In Pydantic v2, `pydantic.ValidatedFunction` is deprecated. Use `pydantic_function_models.ValidatedFunction` as its modern replacement for modeling function signatures.","wrong":"from pydantic import ValidatedFunction","symbol":"ValidatedFunction","correct":"from pydantic_function_models import ValidatedFunction"}],"quickstart":{"code":"from pydantic_function_models import ValidatedFunction\n\ndef add(a: int, b: int) -> int:\n    return a + b\n\nvf = ValidatedFunction(add)\n\n# Example of validating arguments\nargs_to_validate = (1,)\nkwargs_to_validate = {\"b\": 2}\n\n# The library builds an internal Pydantic model for validation\n# You need to map positional/keyword args to model fields\nvalidated_data = vf.model.model_validate({\n    \"a\": args_to_validate[0],\n    \"b\": kwargs_to_validate[\"b\"]\n})\n\nresult = add(**validated_data.model_dump(exclude_unset=True))\nprint(f\"Result: {result}\")\n\n# Example of invalid input\ntry:\n    invalid_data = vf.model.model_validate({\"a\": \"one\", \"b\": 2})\nexcept Exception as e:\n    print(f\"Validation error caught: {e}\")","lang":"python","description":"This example demonstrates how to wrap a Python function with `ValidatedFunction` to enable Pydantic-style argument validation. It shows both successful validation and how `ValidationError` is raised for invalid inputs."},"warnings":[{"fix":"Migrate usage from `pydantic.ValidatedFunction` to `pydantic_function_models.ValidatedFunction` to ensure compatibility and leverage Pydantic v2's features.","message":"The `ValidatedFunction` class from Pydantic v1 is deprecated in Pydantic v2. This library provides a compatible `ValidatedFunction` for Pydantic v2 environments.","severity":"deprecated","affected_versions":"Pydantic >= 2.0"},{"fix":"Rename function parameters if they clash with `v__args` or `v__kwargs` to prevent unexpected behavior.","message":"Avoid using reserved parameter names such as `v__args` and `v__kwargs` in your function signatures, as these could conflict with the internal validation logic of `pydantic-function-models`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider using `from pydantic import validate_call` directly on your function if only argument validation is required, rather than full signature modeling.","message":"For simple function argument validation without needing the full function signature modeling provided by `ValidatedFunction`, Pydantic v2 offers the `@validate_call` decorator, which might be a more direct solution.","severity":"gotcha","affected_versions":"Pydantic >= 2.0"},{"fix":"Ensure a consistent Pydantic version across your codebase or use compatibility tools if incremental migration is necessary. Refer to Pydantic's official migration guide.","message":"Mixing Pydantic v1 and v2 models within a single application can lead to compatibility issues, especially with nested models. While `pydantic-function-models` helps with function validation, general migration strategies for `BaseModel` compatibility should be followed.","severity":"gotcha","affected_versions":"Applications transitioning from Pydantic v1 to v2"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}