High severity intermediate · Fix: 2-5 min

ValidationError

pydantic.error_wrappers.ValidationError

What this error means
The Instructor library raised a Pydantic ValidationError because the input data did not conform to the expected Pydantic model schema.

Stack trace

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

During handling of the above exception, the Instructor library failed to parse the input data according to the Pydantic model.
QUICK FIX
Verify and align your input data dictionary keys and types exactly with the Instructor Pydantic model fields before instantiation.

Why it happens

Instructor uses Pydantic models to validate input data structures strictly. This error occurs when the data passed to the model is missing required fields, has incorrect field names, or contains data types that do not match the model's schema. This mismatch causes Pydantic to raise a ValidationError.

Detection

Catch ValidationError exceptions around Instructor model instantiations and log the input data to identify missing or mismatched fields before the application crashes.

Causes & fixes

1

Input dictionary keys do not match the Pydantic model field names exactly (case-sensitive).

✓ Fix

Ensure that all keys in the input data dictionary match the Pydantic model's field names exactly, including case.

2

Required fields defined in the Pydantic model are missing from the input data.

✓ Fix

Add all required fields to the input data before passing it to the Instructor model.

3

Input data fields have incorrect data types that do not conform to the Pydantic model schema.

✓ Fix

Convert or validate input data types to match the expected types defined in the Pydantic model.

4

Using an outdated or incompatible version of the Instructor library or Pydantic causing schema mismatches.

✓ Fix

Upgrade Instructor and Pydantic to compatible versions as per the library documentation.

Code: broken vs fixed

Broken - triggers the error
python
from instructor import InstructorModel

input_data = {'text': 'Example text'}  # Missing required fields
model = InstructorModel(**input_data)  # This line raises ValidationError
Fixed - works correctly
python
import os
from instructor import InstructorModel

input_data = {
    'text': 'Example text',
    'embedding_dim': 768  # Added required field
}
model = InstructorModel(**input_data)  # Fixed: all required fields present
print('Model created successfully:', model)
Added all required fields to the input dictionary to match the Pydantic model schema, preventing ValidationError on instantiation.

Workaround

Wrap the model instantiation in try/except ValidationError, then log or inspect the raw input data to manually fix missing or mismatched fields before retrying.

Prevention

Use strict type checking and schema validation tools during development to ensure input data always matches the Instructor Pydantic model schema before runtime.

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

Community Notes

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