ValueError
instructor.exceptions.ValueError
Stack trace
ValueError: Missing required 'response_model' field in Instructor call configuration
File "/usr/local/lib/python3.10/site-packages/instructor/sdk.py", line 123, in call
raise ValueError("Missing required 'response_model' field") Why it happens
The Instructor SDK expects a response_model field to be explicitly defined to know how to parse and validate the LLM's output. If this field is omitted, the SDK cannot process the response, causing a ValueError.
Detection
Check your Instructor call configuration for the presence of the response_model field before making the API call, or catch ValueError exceptions and log the missing field error.
Causes & fixes
The response_model field is not set in the Instructor call parameters.
Add a valid response_model parameter specifying the expected output schema or Pydantic model to the Instructor call.
Typo or incorrect field name used instead of response_model.
Correct the parameter name to exactly 'response_model' with proper casing in the Instructor call.
Using an outdated version of the Instructor SDK that requires explicit response_model but it was omitted.
Upgrade to the latest Instructor SDK version and ensure response_model is provided as per the updated API.
Code: broken vs fixed
from instructor import Instructor
client = Instructor()
# Missing response_model causes error
result = client.call(prompt="Summarize this text") # ValueError here import os
from instructor import Instructor
from pydantic import BaseModel
os.environ['INSTRUCTOR_API_KEY'] = os.environ.get('INSTRUCTOR_API_KEY', '')
class SummaryModel(BaseModel):
summary: str
client = Instructor()
# Added response_model to fix error
result = client.call(prompt="Summarize this text", response_model=SummaryModel)
print(result.summary) Workaround
Catch the ValueError exception, then manually parse the raw LLM output string using your own JSON or regex parsing logic as a fallback.
Prevention
Always define and validate a response_model schema when calling Instructor to ensure output parsing is explicit and reliable.