Repository navigation
Description
Description
What happened?
When using the OpenAI Responses client (OpenAIChatCompletionClient) with structured outputs
(response_format), if the backend returns a response body that is a plain string instead of
a structured OpenAI Response object, raw_response.parse() returns a str and the
framework crashes while iterating response.output:
Exception: ChatClientException: ("<class 'agent_framework_openai._chat_client.OpenAIChatClient'> service failed to complete the prompt: 'str' object has no attribute 'output'", AttributeError("'str' object has no attribute 'output'"))
File "agent_framework_openai/_chat_client.py", line 727, in _get_response
response = raw_response.parse()
File "openai/_legacy_response.py", line 139, in parse
parsed = self._options.post_parser(parsed)
File "openai/resources/responses/responses.py", line 2942, in parser
return parse_response(...)
File "openai/lib/_parsing/_responses.py", line 61, in parse_response
for output in response.output:
AttributeError: 'str' object has no attribute 'output'
What did you expect to happen?
A robust, actionable error reporting that the provider returned a non-OpenAI-compliant
response (ideally including the raw payload for debugging) — not an internal AttributeError
crash.
Steps to reproduce the issue
- Configure the Python Agent Framework
OpenAIChatClientagainst an OpenAI-compatible
backend / proxy / gateway that may return a plain string or non-spec body (e.g. an HTML or
text error page on failure/throttling). - Issue a request that uses structured output (
options={"response_format": SomeModel}). - Cause the backend to return a non-conformant body.
- The client crashes with the stack trace above.
Remediation suggestion
Defensively check the parsed response type in _inner_get_response / _parse_response_from_openai
before accessing response.output, and raise a targeted ChatClientException that includes
the raw payload when the response is not a valid Response / ParsedResponse. This mirrors the
hardening already applied elsewhere for OpenAI-compatible provider schema drift.
This is the same class of problem as #6234 (system_fingerprint), but on the Responses
(structured outputs) code path.
Code Sample
from agent_framework_openai import OpenAIChatCompletionClient
from pydantic import BaseModel
class _Response(BaseModel):
summary: str
# Point to a proxy / self-hosted / custom OpenAI-compatible backend:
client = OpenAIChatClient(base_url="https://proxy-or-selfhosted-openai-endpoint/v1")
# Structured output request (response_format) as used in the validation agent:
response = await client.get_response(
messages=messages,
options={"response_format": _Response},
)
# If the backend replies with a plain string / HTML error body, the crash above occurs.Error Messages / Stack Traces
Exception: ChatClientException: ("<class 'agent_framework_openai._chat_client.OpenAIChatClient'> service failed to complete the prompt: 'str' object has no attribute 'output'", AttributeError("'str' object has no attribute 'output'"))
File "/home/site/wwwroot/.python_packages/lib/site-packages/agent_framework_openai/_chat_client.py", line 727, in _get_response
response = raw_response.parse()
File "/home/site/wwwroot/.python_packages/lib/site-packages/openai/_legacy_response.py", line 139, in parse
parsed = self._options.post_parser(parsed)
File "/home/site/wwwroot/.python_packages/lib/site-packages/openai/resources/responses/responses.py", line 2942, in parser
return parse_response(
File "/home/site/wwwroot/.python_packages/lib/site-packages/openai/lib/_parsing/_responses.py", line 61, in parse_response
for output in response.output:
AttributeError: 'str' object has no attribute 'output'Package Versions
agent-framework: 1.6.0
Python Version
Python 3.12
Additional Context
Related to the schema-mismatch bug tracked in #6234 (system_fingerprint). The crash occurs at agent_framework_openai/_chat_client.py line 727 (raw_response.parse()), then in the OpenAI SDK at openai/lib/_parsing/_responses.py line 61 (for output in response.output). Likely caused by a non-OpenAI / OpenAI-compatible backend returning a plain text or HTML body (e.g. on error/throttling). Suggest hardening with a type guard and surfacing the raw payload.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Shaik-Vaheed-UP commentedon Jun 1, 2026
The issues is with OpenAIChatCompletionClient
github-actions commentedon Jun 1, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
Repro: OpenAIChatClient._parse_response_from_openai() in python/packages/openai/agent_framework_openai/_chat_client.py:1971 crashes with AttributeError when the
responseparameter is astrinstead of an OpenAI Response object. Trigger: raw_response.parse() (line 733) returns a non-Response type from a non-conformant backend. Minimal repro: mock client.responses.{parse,create} to return a MagicMock whose .parse() returns a plain string, then call client.get_response(); the AttributeError escapes unhandled because line 736 (_parse_response_from_openai call) is outside the try/except at lines 728-735.python/packages/openai/tests/openai/test_repro_6235.py1.6.01.7.0fix: use typed variable for response output to satisfy pyright
fix: rename response_outputs to avoid name collision with case-block …
fix: use cast(list[Any]) for response output to satisfy pyright
fix: use hasattr guard instead of getattr for response.output
Shaik-Vaheed-UP commentedon Jun 5, 2026
Hi.. When it will be released?
Python: fix: use getattr for non-OpenAI provider response compatibili…