Skip to content

fix: re-raise InputCheckError/OutputCheckError in non-streaming run functions#7636

Closed
VANDRANKI wants to merge 1 commit intoagno-agi:mainfrom
VANDRANKI:fix/output-check-error-propagation
Closed

fix: re-raise InputCheckError/OutputCheckError in non-streaming run functions#7636
VANDRANKI wants to merge 1 commit intoagno-agi:mainfrom
VANDRANKI:fix/output-check-error-propagation

Conversation

@VANDRANKI
Copy link
Copy Markdown

Summary

The documentation shows callers using try/except OutputCheckError around agent.run() and agent.arun() to handle output validation failures. This pattern was silently broken: the four non-streaming entry points (_run, _arun, _continue_run, _acontinue_run) caught the exception, logged it, and returned the run response as if nothing went wrong - the caller's except block was never reached.

Root cause: the except clause ended with return run_response instead of raise.

Changes

  • libs/agno/agno/agent/_run.py: In the except (InputCheckError, OutputCheckError) block of each non-streaming function, replace return run_response with raise.
    • def _run (~line 659)
    • async def _arun (~line 1754)
    • def _continue_run (~line 3064)
    • async def _acontinue_run (~line 3862)

Session cleanup and storage are performed before the re-raise, so persistence is unaffected.

What stays the same

The streaming variants (_run_stream, _arun_stream, _continue_run_stream, _acontinue_run_stream) already surface the error correctly by yielding a RunErrorEvent to the caller's event loop. Those are unchanged.

Reproduces fix for issue #7414

Before:

try:
    result = await agent.arun("What is the capital of France?")
    print(result.content)  # prints "Paris" - validation failure ignored
except OutputCheckError as e:
    print(f"Validation failed: {e}")  # never reached

After:

try:
    result = await agent.arun("What is the capital of France?")
    print(result.content)
except OutputCheckError as e:
    print(f"Validation failed: {e}")  # now correctly raised

Fixes #7414

…un functions

Previously, `_run`, `_arun`, `_continue_run`, and `_acontinue_run` caught
`InputCheckError` / `OutputCheckError`, logged the error, performed session
cleanup, and then returned the run response silently. This made the
try/except pattern shown in the documentation completely ineffective - callers
had no way to distinguish a validation failure from a normal successful run.

The fix replaces `return run_response` with `raise` in the four non-streaming
entry points. Session cleanup and storage happen before the re-raise, so
persistence is unaffected. The streaming variants (`_run_stream`,
`_arun_stream`, `_continue_run_stream`, `_acontinue_run_stream`) already
surface the error via a `RunErrorEvent` yielded to the caller, which is the
appropriate contract for a generator-based API.

Fixes agno-agi#7414

Co-Authored-By: Waston-Li <[email protected]>
@github-actions
Copy link
Copy Markdown
Contributor

PR Triage

A few things to address before this PR can be reviewed:

Missing tests: This PR modifies source code but does not include any test changes. Please add or update tests to cover your changes.


Possible duplicate: The following open PRs also reference the same issue(s):

If this is intentional, please explain in your PR description why this approach is preferred. Otherwise, consider collaborating on the existing PR instead.


This PR has been automatically closed. There is already an open PR addressing this issue. If you believe your contribution is valuable, please comment on the original issue explaining your approach and why it might be preferred. A maintainer can reopen this PR if appropriate.

@github-actions github-actions Bot closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OutputCheckError not raised to caller in post-hook output validation — caught internally and logged instead

1 participant