ValidationError
pydantic.error_wrappers.ValidationError
Stack trace
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
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
Using Instructor with Pydantic v2 while models are defined for Pydantic v1 syntax and semantics
Downgrade Pydantic to v1.x to match Instructor's expected version or upgrade Instructor to a version compatible with Pydantic v2.
Field definitions in Instructor Pydantic models use deprecated or changed syntax incompatible with Pydantic v2
Update field definitions to use Pydantic v2 syntax, including new ways to declare fields and validators.
Instructor library version does not support Pydantic v2 yet
Check Instructor release notes and upgrade to a version that explicitly supports Pydantic v2 or pin Pydantic to v1.
Code: broken vs fixed
from instructor import InstructorConfig
config = InstructorConfig(field_name='value') # triggers ValidationError with Pydantic v2 import os
os.environ['PYDANTIC_VERSION'] = '1'
from instructor import InstructorConfig
config = InstructorConfig(field_name='value') # works with Pydantic v1 compatibility
print(config) 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.