Pydantic v2 adapter for valbridge -- generates native Pydantic BaseModel classes for valbridge's Zod/Pydantic conversion pipeline.
Installation
pip install valbridge-pydantic pydantic
# or
uv add valbridge-pydantic pydantic
Verified against pydantic 2.12.5.
Usage
This adapter is invoked by the valbridge CLI. It is typically used when converting from Zod or other valbridge-supported schema sources into Pydantic models:
// user.valbridge.jsonc
{
"$schema": "https://github.com/vectorfy-co/valbridge/schemas/python.jsonc",
"schemas": [
{
"id": "User",
"adapter": "vectorfyco/valbridge-pydantic",
"sourceType": "file",
"source": "./schemas/user.json"
}
]
}
Then generate:
valbridge generate
Use the generated models with the valbridge runtime client.
Verification
Run from the adapter directory (python/packages/adapters/pydantic/):
# JSON Schema Test Suite compliance (requires Go CLI)
cd ../../cli && go build -o valbridge . && \
./valbridge compliance --lang python --adapter-path ../python/packages/adapters/pydantic
# Unit tests
uv run pytest
# Type checking
uv run pyright src/
Fallback typing guardrails
The adapter uses Annotated[Any, BeforeValidator(...)] only for constructs where the validated domain is unbounded. Every other construct must produce a narrower type.
Allowed Any fallbacks
| Construct | Reason |
|---|---|
not |
Negation is "everything except X" -- no union can express this |
conditional (single branch) |
Unmatched values pass through unconstrained |
typeGuarded (heterogeneous) |
Unmatched types pass through the guard |
| Open tuple | Extra elements beyond prefix items are untyped |
| Recursive refs | Self-referencing $ref cycles |
Constructs that must NOT use Any
oneOf-- must produceT1 | T2 | ...conditional(if/then/else) -- must produceThenType | ElseType- Closed tuples -- must produce
tuple[T1, T2, ...] const/enum-- must produce the narrowest applicable typeallOf(object merges) -- must produce a BaseModel subclass
Disallowed patterns
- Unknown IR node kind -- must raise
ConversionError - Unresolved external refs -- must raise
ConversionError - New renderer branches must not silently return
Anywithout documented justification
Troubleshooting
- pyright errors -- adapter source must pass
uv run pyright src/with zero errors - Compliance failures -- run full compliance and compare against baseline; check that validator lambdas are functionally identical
Related packages
| Package | Purpose |
|---|---|
valbridge |
Runtime client for generated validators |
valbridge-core |
Core IR and JSON Schema parser |
valbridge-pydantic-bridge |
Bridge helpers for Pydantic generation |
@vectorfyco/valbridge-zod |
TypeScript equivalent (Zod adapter) |
Learn more
Metadata
Release files for valbridge-pydantic 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| valbridge_pydantic-1.2.0.tar.gz | 61.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| valbridge_pydantic-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 98.8 kB
Release files / valbridge_pydantic-1.2.0.tar.gz
| Download URL | valbridge_pydantic-1.2.0.tar.gz |
|---|---|
| Size | 61.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7226dcb63ebdc543596123bfbc11b3d014c61cc55c50d6ed756ce90e45fc348
|
|
BLAKE2b-256 checksum How to use checksums |
1846e67934df9886ad4b2a1c21a3b18554aacb084c115f6752a1ca52efe1858c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 10, 2026.
Transparency logRelease files / valbridge_pydantic-1.2.0-py3-none-any.whl
| Download URL | valbridge_pydantic-1.2.0-py3-none-any.whl |
|---|---|
| Size | 36.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b03fe9e82d5ef3103ad6af1dce5aa373b2ecc856d6e252362687cd950baee606
|
|
BLAKE2b-256 checksum How to use checksums |
d739bee037dad4d5d312217fca48395090386c9f827071c94884f6daed22e47b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 10, 2026.
Transparency log