Description
I have followed instructions on Input validation pre hook. But the code does not reach: except InputCheckError as e
Steps to Reproduce
- Install
agno==2.5.17
- Go to the Input validation pre hook page.
- Copy the template code and run it
Agent Configuration (if applicable)
Validator Agent:
validator_agent = Agent(
name="Input Validator",
model=OpenAIChat(id="gpt-4o-mini"),
instructions=[
"You are an input validation specialist. Analyze user requests for:",
"1. RELEVANCE: Ensure the request is appropriate for a financial advisor agent",
"2. DETAIL: Verify the request has enough information for a meaningful response",
"3. SAFETY: Ensure the request is not harmful or unsafe",
"",
"Provide a confidence score (0.0-1.0) for your assessment.",
"List specific concerns and recommendations for improvement.",
"",
"Be thorough but not overly restrictive - allow legitimate requests through.",
],
output_schema=InputValidationResult,
)
Main agent:
agent = Agent(
name="Financial Advisor",
model=OpenAIChat(id="gpt-4o-mini"),
pre_hooks=[comprehensive_input_validation],
description="A professional financial advisor providing investment guidance and financial planning advice.",
instructions=[
"You are a knowledgeable financial advisor with expertise in:",
"• Investment strategies and portfolio management",
"• Retirement planning and savings strategies",
"• Risk assessment and diversification",
"• Tax-efficient investing",
"",
"Provide clear, actionable advice while being mindful of individual circumstances.",
"Always remind users to consult with a licensed financial advisor for personalized advice.",
],
)
Expected Behavior
InputCheckError raised and must be caught by: except InputCheckError as e
Actual Behavior
Not be caught by the exception statement and printed by the print function
Screenshots or Logs (if applicable)
The output results are below. I can't see any logs from:
print(f"❌ Pre-hook validation failed: {e}")
print(f" Trigger: {e.check_trigger}")
Actual result logs:
🔴 Test 2: Vague input (insufficient detail)
----------------------------------------
ERROR Validation failed: Input lacks sufficient detail
for a meaningful response. Suggestions: Encourage
the user to provide more context such as their
investment experience, the amount they wish to
invest, their risk tolerance, and specific areas
of interest (e.g., stocks, bonds, real estate). |
Check trigger: CheckTrigger.INPUT_NOT_ALLOWED
Input lacks sufficient detail for a meaningful response. Suggestions: Encourage the user to provide more context such as their investment experience, the amount they wish to invest, their risk tolerance, and specific areas of interest (e.g., stocks, bonds, real estate).
🔴 Test 3: Off-topic request
----------------------------------------
ERROR Validation failed: Input is not relevant to
financial advisory services. Rephrase the request
to relate to financial advice, for example, 'How
can I budget for my grocery expenses including
pizza ingredients?' | Check trigger:
CheckTrigger.OFF_TOPIC
Input is not relevant to financial advisory services. Rephrase the request to relate to financial advice, for example, 'How can I budget for my grocery expenses including pizza ingredients?'
🔴 Test 4: Potentially unsafe content
----------------------------------------
ERROR Validation failed: Input is harmful or unsafe.
Provide information on legitimate investment
strategies instead. | Check trigger:
CheckTrigger.INPUT_NOT_ALLOWED
Input is harmful or unsafe. Provide information on legitimate investment strategies instead.
Environment
- Agno version: 2.5.17
- OpenAI version: 2.15.0
Possible Solutions (optional)
No response
Additional Context
No response
Description
I have followed instructions on Input validation pre hook. But the code does not reach: except InputCheckError as e
Steps to Reproduce
agno==2.5.17Agent Configuration (if applicable)
Validator Agent:
Main agent:
Expected Behavior
InputCheckError raised and must be caught by: except InputCheckError as e
Actual Behavior
Not be caught by the exception statement and printed by the print function
Screenshots or Logs (if applicable)
The output results are below. I can't see any logs from:
Actual result logs:
Environment
Possible Solutions (optional)
No response
Additional Context
No response