Skip to main content
A pre-hook checks relevance, detail, and safety before model execution. Blocked calls return a run output with RunStatus.error.
The source catches InputCheckError around blocked Agent.run() calls. Agno v2.7.2 converts the pre-hook exception into a run output with RunStatus.error, so those except blocks are bypassed. Check each blocked response’s status instead.
pre_hook_input.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Check blocked run statuses

Add from agno.run import RunStatus. For tests 2 through 4, replace each complete try/except InputCheckError block with response = agent.run(...) followed by a branch that handles response.status == RunStatus.error as a blocked call.
5

Run the example

Save the code above as pre_hook_input.py, then run:
Full source: cookbook/02_agents/09_hooks/pre_hook_input.py