Parallel tools fail to dispatch custom Pydantic schema titles
- [x] This is actually a bug report.
- [x] I have tried searching the documentation and have not found an answer.
Describe the bug
OpenAI and Anthropic parallel tool declarations use the Pydantic JSON schema title as the function name. Their response parsers build registries using Python class names. A model with ConfigDict(title="extract_value") therefore sends extract_value to the provider, but a valid response with that name produces an empty result through the current parallel handlers. The legacy OpenAI ParallelModel.from_response() raises KeyError.
When two models' titles match each other's class names, both providers can silently select the wrong model class. Separate models sharing a class name also fail to dispatch by their distinct schema titles.
To reproduce
This uses a real OpenAI SDK response object and requires no network request or API key:
from collections.abc import Iterable
from openai.types.chat import ChatCompletion
from pydantic import BaseModel, ConfigDict
from instructor.v2.providers.openai.handlers import OpenAIParallelToolsHandler
class Extract(BaseModel):
model_config = ConfigDict(title="extract_value")
value: int
handler = OpenAIParallelToolsHandler()
_, request = handler.prepare_request(Iterable[Extract], {"messages": []})
name = request["tools"][0]["function"]["name"]
response = ChatCompletion.model_validate({
"id": "chatcmpl-test", "created": 0, "model": "gpt-4o-mini",
"object": "chat.completion",
"choices": [{
"index": 0, "finish_reason": "tool_calls",
"message": {"role": "assistant", "tool_calls": [{
"id": "call_1", "type": "function",
"function": {"name": name, "arguments": '{"value": 1}'},
}]},
}],
})
print(name) # extract_value
print(list(handler.parse_response(response, Iterable[Extract]))) # []
Expected behavior
The result is [Extract(value=1)]. Each parallel response should resolve to the model whose tool declaration advertised that name. Vertex AI's existing class-name declarations should keep matching their parser.
Environment
Latest main e12f8b49203b0c1f253d27c1e709d0a09b9fc5a8, Instructor 1.17.1, Python 3.12.13, Windows. Verified against the project's frozen dependency lock. Regression coverage uses OpenAI ChatCompletion, Anthropic Message, and Vertex AI GenerationResponse objects without live provider requests.
Issue #1174 concerns a provider inventing an undeclared tool name; this reproduction returns the exact tool name declared in the request.