High severity intermediate · Fix: 5-15 min

ValidationError

pydantic.error_wrappers.ValidationError

What this error means
The Instructor library's Pydantic models fail validation due to breaking changes between Pydantic v1 and v2 schemas.

Stack trace

traceback
pydantic.error_wrappers.ValidationError: 1 validation error for InstructorConfig
field_name
  field required (type=value_error.missing)

During handling of the above exception, another error occurred:

instructor.exceptions.InstructorConfigError: Failed to parse InstructorConfig due to Pydantic validation error
QUICK FIX
Pin Pydantic to version 1.x in your environment to restore compatibility with Instructor models immediately.

Why it happens

Instructor uses Pydantic models to validate configuration and data schemas. Pydantic v2 introduced breaking changes in model initialization and field handling, causing models written for v1 to fail validation or raise errors when run with v2. This incompatibility leads to ValidationError exceptions.

Detection

Monitor logs for pydantic.error_wrappers.ValidationError exceptions during Instructor model instantiation, especially after upgrading Pydantic or Instructor versions.

Causes & fixes

1

Using Instructor with Pydantic v2 while models are defined for Pydantic v1 syntax and semantics

✓ Fix

Downgrade Pydantic to v1.x to match Instructor's expected version or upgrade Instructor to a version compatible with Pydantic v2.

2

Field definitions in Instructor Pydantic models use deprecated or changed syntax incompatible with Pydantic v2

✓ Fix

Update field definitions to use Pydantic v2 syntax, including new ways to declare fields and validators.

3

Instructor library version does not support Pydantic v2 yet

✓ Fix

Check Instructor release notes and upgrade to a version that explicitly supports Pydantic v2 or pin Pydantic to v1.

Code: broken vs fixed

Broken - triggers the error
python
from instructor import InstructorConfig
config = InstructorConfig(field_name='value')  # triggers ValidationError with Pydantic v2
Fixed - works correctly
python
import os
os.environ['PYDANTIC_VERSION'] = '1'
from instructor import InstructorConfig
config = InstructorConfig(field_name='value')  # works with Pydantic v1 compatibility
print(config)
Pinned Pydantic to v1 to maintain compatibility with Instructor's Pydantic models, preventing validation errors caused by v2 changes.

Workaround

Catch ValidationError exceptions when creating InstructorConfig and manually adjust or coerce input data to match expected schema fields until a full upgrade is possible.

Prevention

Use explicit version constraints for Pydantic and Instructor in your dependency management to avoid incompatible upgrades and test model instantiation after any dependency changes.

Python 3.9+ · instructor >=0.1.0 · tested on 0.4.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.