BasicsRoutingWorkflowsOpenAIAnthropicGoogle
Problem
Implement route_query(query) that classifies a user message (case-insensitive) into one of three specialist queues: 'billing' if it contains 'refund', 'invoice', or 'billing'; else 'code' if it contains 'bug', 'error', or 'python'; else 'general'.
Why It Matters: Fast deterministic intent routers handle obvious triage in microseconds before falling back to expensive LLM classification calls.
Function Signature
def route_query(query: str) -> str:
"""Route query to 'billing', 'code', or 'general' using keyword rules."""
Sample Input & Output
Example 1: Billing Priority Route
Input:
query = "Please send my INVOICE and check for a refund"
Expected Output:
"billing"
Explanation: Case-insensitive matching detects 'invoice' / 'refund' and routes to 'billing'.
Example 2: Code vs. General Fallback
Input:
route_query("Python TypeError bug") | route_query("What are your hours?")
Expected Output:
"code" | "general"
Explanation: Code keywords trigger 'code'; unmatched messages safely fall back to 'general'.
Example 3: Precedence When Both Match
Input:
query = "Billing page throws a Python error"
Expected Output:
"billing"
Explanation: 'billing' is evaluated before 'code', so 'billing' wins precedence.
Constraints & Edge Cases
- Return
'billing','code', or'general'. - Perform matching on
query.lower(). - Respect strict rule order:
'billing'->'code'->'general'.
Constraints & Evaluation Criteria
- Return `'billing'`, `'code'`, or `'general'`.
Hints
Learn the Concept First
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
3 sample queries
Expected Output / Criteria
'billing', 'code', 'general'