Skip to content

fix: extend output_text to include code_interpreter and shell output#2925

Open
roli-lpci wants to merge 1 commit intoopenai:mainfrom
roli-lpci:fix/output-text-tool-results
Open

fix: extend output_text to include code_interpreter and shell output#2925
roli-lpci wants to merge 1 commit intoopenai:mainfrom
roli-lpci:fix/output-text-tool-results

Conversation

@roli-lpci
Copy link

Summary

The output_text convenience property only aggregates text from message output items. When a response contains code_interpreter_call or shell_call_output items with textual results but no accompanying message, output_text returns an empty string.

This extends the property to also collect:

  • code_interpreter_call: log output from OutputLogs.logs
  • shell_call_output: stdout from Output.stdout

Root Cause

Despite the report in #2870, the SDK code between v2.19.0 and v2.20.0 is unchanged for this codepath — output_text has always only traversed message-type output items:

# Before (v2.19.0 through v2.24.0 — identical)
for output in self.output:
    if output.type == "message":  # ← only messages
        for content in output.content:
            if content.type == "output_text":
                texts.append(content.text)

Code interpreter results live in code_interpreter_call items via outputs[].logs, which is a separate data path that output_text never traversed. This is a feature gap in the convenience property, not a deserialization regression.

Changes

  • src/openai/types/responses/response.py — Extend output_text to also iterate code_interpreter_call log outputs and shell_call_output stdout. Updated docstring to reflect the expanded aggregation.
  • tests/lib/responses/test_responses.py — 6 new tests:
    • Mixed message + code interpreter output (ordering preserved)
    • Code interpreter only (no message item)
    • outputs: null (graceful empty string)
    • Image-only outputs (correctly skipped)
    • Shell call stdout

Scope note

This PR covers code_interpreter_call and shell_call_output as the two tool types with unambiguous textual output. Other tool types (mcp_call, apply_patch_call_output) could be added in a follow-up if desired.

Testing

All 110 tests/lib/ tests pass, including the 6 new ones.

Fixes #2870

The `output_text` convenience property only aggregated text from
`message` output items, silently returning an empty string when the
response contained `code_interpreter_call` or `shell_call_output`
items with textual results.

This extends the property to also collect:
- Log output from `code_interpreter_call` items (OutputLogs.logs)
- Stdout from `shell_call_output` items (Output.stdout)

Adds 6 regression tests covering: mixed output, code-interpreter-only,
null outputs, image-only outputs, and shell call output.

Fixes openai#2870

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@roli-lpci roli-lpci requested a review from a team as a code owner March 3, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responses API with code_interpreter returns empty output_text in v2.20.0 (regression from v2.19.0)

1 participant