The Problem
You built a financial advisor agent that should only answer questions about investments, stocks, budgeting, and personal finance. In practice, users ask it about everything — medical symptoms, legal advice, cooking recipes — and the agent happily obliges because there is no topic enforcement. The system prompt says "financial advisor" but the LLM doesn't reliably refuse off-topic queries on its own. Your job is to add a topic guard that checks whether the user's question falls within the finance domain and politely redirects off-topic requests.
Examples
Example 1
User input: What are the symptoms of diabetes?
Current (bad) output: The agent provides a detailed medical answer about diabetes symptoms, acting as a doctor.
Expected (good) output: "I'm a financial advisor and can only help with finance-related questions. For medical concerns, please consult a healthcare professional."
Example 2
User input: What's the best way to invest $10,000?
Current (bad) output: (This is fine — an on-topic question gets a normal answer.)
Expected (good) output: The agent provides investment advice as expected, since this is within its domain.
Example 3
User input: Write me a poem about the ocean
Current (bad) output: The agent writes a creative poem, completely outside its finance scope.
Expected (good) output: "I appreciate the creative request, but I'm specialized in financial advice. For creative writing, you might try a general-purpose assistant."
Your Task
Add a topic restriction guard so the agent:
- Checks whether the user's query is related to finance before processing it.
- Politely declines off-topic questions with a redirect suggestion.
- Continues to answer finance-related questions normally.
- Does not rely solely on the system prompt for topic enforcement.
Evaluation
Submissions are checked for the following:
- Off-topic queries are rejected: Questions outside the finance domain are politely declined.
- On-topic queries are answered: Finance-related questions still get helpful answers.
- Polite redirect provided: Off-topic rejections include a suggestion to seek help elsewhere.