beta.agents: AgentTurnResult.parse() swallows TypeError for invalid output_type and raises AgentOutputParseError
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
バグは src/openai/lib/beta/agents/_result.py の AgentTurnResult.parse() にあり、そこで validate_output_type が広い except Exception の内側で実行されています。まずそのメソッドと、tests/lib/streaming/agents/test_output.py にある既存のチェック(test_invalid_output_model_rejected_before_request)を読んでください。検証呼び出しを try: の上に移動し、parse(str)、parse(dict)、parse(object) が AgentOutputParseError を伴わずに TypeError を送出することを確認する同期および非同期の回帰テストを追加してください。これらのテストが通り、agents のテストスイートも引き続き通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
In src/openai/lib/beta/agents/_result.py:32-51, AgentTurnResult.parse() invokes validate_output_type(output_type) inside the broad try: ... except Exception: block:
def parse(self, output_type: type[ParseT]) -> AgentTurnResult[ParseT]:
"""Beta: parse a completed answer without changing its session configuration."""
try:
validate_output_type(output_type)
parsed: ParseT | None = None
...
except Exception:
# Pydantic errors may include response text in their rendered message.
raise AgentOutputParseError(self) from None
When a caller passes an unsupported output_type (such as str, dict, or object), validate_output_type(output_type) raises TypeError("Agents output_type must be a Pydantic model or a Pydantic v2 dataclass"), which is immediately caught, stripped of its cause (from None), and re-raised as AgentOutputParseError("Could not parse the completed agent output").
This disguises a caller-side programming/configuration error as a malformed model output error and is inconsistent with sessions.create(..., output_type=...) and sessions.stream(..., output_type=...), both of which propagate TypeError directly (covered by test_invalid_output_model_rejected_before_request in tests/lib/streaming/agents/test_output.py:456-477).
To Reproduce
- Obtain an
AgentTurnResultfrom a completed agent turn (e.g.stream.get_final_result()). - Call
result.parse(str),result.parse(dict), orresult.parse(object). - Observe that
AgentOutputParseError(__cause__=None) is raised instead ofTypeError.
Code snippets
from openai.lib.beta.agents import AgentTurnResult
from openai.types.beta.agent_session_message import AgentSessionMessage
from openai.types.beta.agents.sessions.turn import Turn
turn = Turn.construct(
id="turn_1", object="agent.session.turn", agent_id="a", session_id="s", created_at=1, status="completed"
)
msg = AgentSessionMessage.construct(
id="msg_1",
type="message",
role="assistant",
status="completed",
turn_id="turn_1",
content=[{"type": "output_text", "text": '{"ok": true}'}],
)
result = AgentTurnResult(turn=turn, messages=[msg])
for bad_type in (str, dict, object):
try:
result.parse(bad_type)
except Exception as exc:
print(f"result.parse({bad_type.__name__}) -> {type(exc).__name__}: {exc} (__cause__={exc.__cause__!r})")
Actual output:
result.parse(str) -> AgentOutputParseError: Could not parse the completed agent output (__cause__=None)
result.parse(dict) -> AgentOutputParseError: Could not parse the completed agent output (__cause__=None)
result.parse(object) -> AgentOutputParseError: Could not parse the completed agent output (__cause__=None)
Expected output:
TypeError: Agents output_type must be a Pydantic model or a Pydantic v2 dataclass
Suggested Fix
Move validate_output_type(output_type) immediately before try: in src/openai/lib/beta/agents/_result.py:
def parse(self, output_type: type[ParseT]) -> AgentTurnResult[ParseT]:
"""Beta: parse a completed answer without changing its session configuration."""
+ validate_output_type(output_type)
try:
- validate_output_type(output_type)
parsed: ParseT | None = None
(Verified locally with sync/async regression tests across str, dict, and object: 519 passed across tests/lib/streaming/agents/, tests/lib/beta/agents/test_tools.py, and tests/test_agents_budget_events.py, with ruff and pyright 0 errors.)
OS
macOS
Python version
Python 3.14.8
Library version
openai v3.57.0 (main@f63f14b)
- 主要言語
- Python
- スター
- 32.2k
- フォーク
- 5.8k
- 平均マージ
- 12時間 29分
- マージ済み PR(30日)
- 112
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/openai-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
openai/openai-python#4338 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
openai/openai-python#4337 ·
メンテナーはふだん 1 日以内に返信
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parameters対応中かも @Rewaskc02-lang が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
openai/openai-python#4311 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
openai/openai-python#4310 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
openai/openai-python#4309 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
openai/openai-python の issue をすべて見る
似ている issue
-
triage
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
kornia/kornia-rs#1416 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
ui
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PolicyEngine/ai-inequality#64 ·
メンテナーはふだん 1 日以内に返信
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over time対応中かも @PabloRoque が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
pymc-devs/pymc-extras#839 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信