dict, set, tuple and Iterable[str] response models fail or return invalid types
Description
There are two major gaps in how simple types are parsed that cause crashes or incorrect objects to be returned:
dict,set, andtuplecrash on schema generation. Providingresponse_model=dict[str, int]orset[int]fails withTypeError: response_model must be a subclass of pydantic.BaseModel, got GenericAliasbecause these standard collection types are missing fromis_simple_type.Iterable[str](and other simple iterables) yield wrapperResponseobjects instead of raw strings. When requestingIterable[str](or int, dict, etc.), the elements yield correctly in the streaming logic but are wrapped in the internalAdapterBase(e.g.Response(content='hello')) instead of just yielding'hello'.
Environment
- instructor==1.17.1
- Python 3.10-3.14
Minimal repro
Bug 1: dict simple type crash
from instructor.v2.core.response_model import prepare_response_model
prepare_response_model(dict[str, int])
# TypeError: response_model must be a subclass of pydantic.BaseModel, got GenericAliasBug 2: Iterable[str] unwrapping failure
from typing import Iterable
from instructor.v2.core.response_model import prepare_response_model
Model = prepare_response_model(Iterable[str])
obj = Model.extract_cls_task_type('{"content": "hello"}')
print(repr(obj))
# Expected: 'hello'
# Actual: Response(content='hello')Expected
- Standard collections like
dict,set, andtupleshould be recognized as simple types and properly adapted. Iterable[simple_type]should unwrap the internal adapter and yield raw elements (e.g.,str,int,dict) to the caller.
Suggested fix direction
- Add
dict,set, andtupleto the explicit simple types inis_simple_type. - In
instructor/v2/core/response_model.py, wrapiterable_element_classinModelAdapterif it is a simple type before passing it toIterableModel. - In
instructor/v2/dsl/iterable.py, unwrapAdapterBaseinsideextract_cls_task_typebefore returning.
Source: 567-labs/instructor