#2613·instructor

`is_simple_type` falsely returns True for custom non-Pydantic classes on Python 3.10+, causing schema generation crashes

Author: Gracy769Created Sep 9, 2026Updated Sep 9, 2026

Summary

When passing a list containing a custom class (that does not inherit from BaseModel) as a response model, Instructor crashes with a confusing PydanticSchemaGenerationError on Python 3.10 and above.

Reproducer

``python from instructor.utils.core import prepare_response_model

class MyClass: pass

model = prepare_response_model(list[MyClass]) ``

Output: pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class '__main__.MyClass'>. ...

Root Cause

In instructor/v2/dsl/simple_type.py, the is_simple_type function contains a check intended to identify Python 3.10+ pipe syntax (|) for Union types:

``python

Check for Python 3.10+ pipe syntax

if hasattr(inner_arg, or): return True ``

However, in Python 3.10, the __or__ method was added directly to the type builtin itself. This means that every single class in Python now returns True for `hasattr(cls, 'or').

Because issubclass(inner_arg, BaseModel) fails for MyClass, it falls through to the hasattr check, which returns True. Instructor then mistakenly assumes list[MyClass] is a 'simple type' and forces it through ModelAdapter.__class_getitem__, which ultimately explodes inside Pydantic.

Suggested Fix

Refine the pipe syntax check. Instead of broadly checking hasattr(inner_arg, '__or__'), we should check if the type is actually a Union, or simply let Pydantic handle validation failures more gracefully instead of forcefully wrapping custom classes.