AttributeError
AttributeError: 'instructor' object has no attribute 'from_openai'
Stack trace
Traceback (most recent call last):
File "app.py", line 12, in <module>
instructor_model = Instructor.from_openai(model_name="text-embedding-3-large") # deprecated
AttributeError: 'instructor' object has no attribute 'from_openai' Why it happens
The Instructor library previously provided a 'from_openai' class method to patch OpenAI models, but recent updates to the OpenAI SDK and Instructor package removed or replaced this method. Using the old method causes AttributeError because it no longer exists.
Detection
Check for AttributeError exceptions mentioning 'from_openai' when instantiating Instructor models; monitor deprecation warnings in logs during startup.
Causes & fixes
Using the deprecated Instructor.from_openai() method which was removed in newer versions.
Replace Instructor.from_openai() with the new recommended initialization pattern using the OpenAI client and Instructor constructor.
Mixing incompatible versions of the Instructor package and OpenAI SDK causing missing methods.
Ensure both Instructor and OpenAI SDK packages are updated to compatible versions as per the latest documentation.
Following outdated tutorials or examples referencing the old 'from_openai' patch method.
Consult the latest Instructor and OpenAI SDK docs for updated usage patterns and refactor code accordingly.
Code: broken vs fixed
from instructor import Instructor
# Deprecated usage causing AttributeError
instructor_model = Instructor.from_openai(model_name="text-embedding-3-large") # deprecated
embedding = instructor_model.encode(["test text"])
print(embedding) import os
from openai import OpenAI
from instructor import Instructor
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
instructor_model = Instructor(client=client, model_name="text-embedding-3-large") # fixed usage
embedding = instructor_model.encode(["test text"])
print(embedding) # prints embedding vector Workaround
If immediate refactor is not possible, wrap the call in try/except AttributeError and fallback to manual OpenAI client creation and Instructor instantiation.
Prevention
Always track and update third-party SDK usage to match official docs; avoid deprecated methods by subscribing to changelogs and upgrading dependencies regularly.