#2719·instructor

dict, set, tuple and Iterable[str] response models fail or return invalid types

Author: Gracy769Created Sep 29, 2026Updated Sep 29, 2026

Description

There are two major gaps in how simple types are parsed that cause crashes or incorrect objects to be returned:

  1. dict, set, and tuple crash on schema generation. Providing response_model=dict[str, int] or set[int] fails with TypeError: response_model must be a subclass of pydantic.BaseModel, got GenericAlias because these standard collection types are missing from is_simple_type.

  2. Iterable[str] (and other simple iterables) yield wrapper Response objects instead of raw strings. When requesting Iterable[str] (or int, dict, etc.), the elements yield correctly in the streaming logic but are wrapped in the internal AdapterBase (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

python
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 GenericAlias

Bug 2: Iterable[str] unwrapping failure

python
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

  1. Standard collections like dict, set, and tuple should be recognized as simple types and properly adapted.
  2. 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, and tuple to the explicit simple types in is_simple_type.
  • In instructor/v2/core/response_model.py, wrap iterable_element_class in ModelAdapter if it is a simple type before passing it to IterableModel.
  • In instructor/v2/dsl/iterable.py, unwrap AdapterBase inside extract_cls_task_type before returning.