Built-in Responses tools (code_interpreter) are dropped: RESPONSES_TOOLS overwrites tools and forces tool_choice
Bug: built-in Responses tools (for example code_interpreter) are dropped in RESPONSES_TOOLS and RESPONSES_TOOLS_WITH_INBUILT_TOOLS.
Summary
The docs say Mode.RESPONSES_TOOLS_WITH_INBUILT_TOOLS "automatically enables OpenAI's built-in tools (web search, file search, etc.) inside the Responses API". Both openai.md and openai-responses.md say so.
In v2 the mode is normalized to RESPONSES_TOOLS. The deprecation warning also recommends RESPONSES_TOOLS. The RESPONSES_TOOLS request handler overwrites the caller's tools with the response-model function tool and forces tool_choice to that function. As a result:
- the built-in tool that the caller passed never reaches the API;
- the forced
tool_choicewould stop the model from calling a built-in tool before it answers, even if the tool were kept.
With code_interpreter, the model answers without running any code. No code_interpreter_call items appear in the output.
Minimal reproduction (no network or API key needed)
import instructor
from instructor.mode import Mode
from instructor.utils.providers import Provider
from instructor.v2.core.registry import mode_registry, normalize_mode
from pydantic import BaseModel
class Answer(BaseModel):
value: int
print("instructor", instructor.__version__)
print("normalized mode:", normalize_mode(Provider.OPENAI, Mode.RESPONSES_TOOLS_WITH_INBUILT_TOOLS))
prepare = mode_registry.get_handler(Provider.OPENAI, Mode.RESPONSES_TOOLS)
_, request = prepare(
Answer,
{
"messages": [{"role": "user", "content": "Sum the first 2000 primes."}],
"tools": [{"type": "code_interpreter", "container": {"type": "auto"}}],
},
)
print("tools sent:", [t["type"] for t in request["tools"]])
print("tool_choice:", request["tool_choice"])Output on 1.16.0 and 1.17.0 (openai 2.28.0):
instructor 1.17.0
normalized mode: Mode.RESPONSES_TOOLS
tools sent: ['function']
tool_choice: {'type': 'function', 'name': 'Answer'}The code_interpreter tool is gone from the request.
Expected: tools holds both the caller's built-in tool and the response-model function tool. tool_choice lets the model call the built-in tool first.
Where it happens
instructor/v2/providers/openai/client.py(_from_openai_compat) mapsRESPONSES_TOOLS_WITH_INBUILT_TOOLStoRESPONSES_TOOLS.instructor/v2/core/mode.pyhas the same mapping.instructor/v2/providers/openai/handlers.py,RESPONSES_TOOLShandler,prepare_request: it setsnew_kwargs["tools"] = [tool_definition]andnew_kwargs["tool_choice"] = {"type": "function", "name": ...}without merging the caller's tools.
Observed effect
We asked o3 and gpt-5.x with code_interpreter for an exact computation ("sum of the first 2000 primes", which is 16274627) through client.responses.create_with_completion(..., tools=[{"type": "code_interpreter", ...}]). They returned a different wrong number on each run, and no code was executed.
Workaround
Call the OpenAI SDK directly. It supports structured output together with built-in tools:
response = await client.responses.parse(
model="o3",
instructions="Use the python tool to compute exactly.",
input=[{"role": "user", "content": [{"type": "input_text", "text": "Sum the first 2000 primes."}]}],
tools=[{"type": "code_interpreter", "container": {"type": "auto"}}],
text_format=Answer,
)
answer = response.output_parsed # 16274627; the output contains code_interpreter_call itemsPossible fix
When the caller passes non-function tools, keep them in tools. Do not force tool_choice to the schema function in that case. One way is to use text.format with a json_schema for the structured result, which is what responses.parse does. That would also match the direction discussed in #2300. Related: #1741 used code_interpreter with this mode.
Versions
- instructor 1.16.0 and 1.17.0;
v2/core/mode.pyonmainhas the same mapping. - openai 2.28.0
- Python 3.12
Source: 567-labs/instructor