Skip to content

Python: [Bug]: OpenAIChatClient fails with 'str' object has no attribute 'output' when provider returns non-OpenAI conformant/structured response #6235

@Shaik-Vaheed-UP

Description

@Shaik-Vaheed-UP

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

  1. Configure the Python Agent Framework OpenAIChatClient against 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).
  2. Issue a request that uses structured output (options={"response_format": SomeModel}).
  3. Cause the backend to return a non-conformant body.
  4. 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

No fields configured for Bug.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions