beta.agents: AgentTurnResult.parse() swallows TypeError for invalid output_type and raises AgentOutputParseError
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 82/100
Línea de trabajo
El bug está en src/openai/lib/beta/agents/_result.py en AgentTurnResult.parse(), donde validate_output_type se ejecuta dentro de un amplio except Exception. Empieza leyendo ese método y la comprobación existente en tests/lib/streaming/agents/test_output.py (test_invalid_output_model_rejected_before_request). Mueve la llamada de validación por encima de try: y añade pruebas de regresión síncronas y asíncronas de que parse(str), parse(dict) y parse(object) lanzan TypeError sin AgentOutputParseError. Terminado cuando esas pruebas pasen y la suite de pruebas de agents siga pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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)
- Lenguaje dominante
- Python
- Estrellas
- 32.2k
- Forks
- 5.8k
- Merge medio
- 12 h 29 min
- PR fusionados (30 d)
- 112
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de openai/openai-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
openai/openai-python#4338 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
openai/openai-python#4337 ·
Los mantenedores suelen responder en 1 día
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersPosiblemente ocupada @Rewaskc02-lang la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4311 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openai/openai-python#4310 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
openai/openai-python#4309 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de openai/openai-python
Issues similares
-
triage
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
kornia/kornia-rs#1416 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
PolicyEngine/ai-inequality#64 ·
Los mantenedores suelen responder en 1 día
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timePosiblemente ocupada @PabloRoque la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
pymc-devs/pymc-extras#839 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día