Last Updated: October 6, 2025 Status: Production Ready Epic: GREAT-4E - Complete Validation
This guide explains when and how to use intent classification in Piper Morgan. As of GREAT-4E completion, intent classification is mandatory for all natural language user input, with 13/13 intent categories fully implemented and validated.
Intent classification MUST be used for:
✅ User text messages - Slack, chat, conversational UI ✅ Free-text queries - Unstructured user input ✅ Ambiguous requests - Need interpretation ✅ Natural language commands - “What’s my schedule?”, “Create an issue”
Intent classification is NOT needed for:
❌ Structured CLI commands - piper documents search --query X
❌ Output processing - Personality enhancement
❌ Direct ID lookups - /api/workflows/12345
❌ Static resources - Health checks, docs, config
Edit web/middleware/intent_enforcement.py:
NL_ENDPOINTS = [
'/api/v1/intent',
'/api/standup',
'/api/chat',
'/api/message',
'/api/your-new-endpoint' # Add here
]
Your endpoint should call the intent classifier:
@app.post("/api/your-new-endpoint")
async def your_endpoint(request: Request):
user_text = request.json().get("text")
# Classify intent
from services.intent_service import classifier
intent = await classifier.classify(user_text)
# Route to appropriate handler
if intent.category == IntentCategory.TEMPORAL:
return await handle_temporal_query(intent)
elif intent.category == IntentCategory.STATUS:
return await handle_status_query(intent)
# ... etc
Or redirect to universal intent endpoint:
@app.post("/api/your-new-endpoint")
async def your_endpoint(request: Request):
# Redirect to universal handler
return await process_intent(request)
Create test in tests/intent/test_user_flows_complete.py:
def test_your_endpoint_flow(self):
response = client.post("/api/your-new-endpoint", json={
"text": "Sample query"
})
assert response.status_code in [200, 422]
# Verify intent was classified
if response.status_code == 200:
data = response.json()
assert "intent" in data or "category" in data
# Run bypass scanner
python scripts/check_intent_bypasses.py
# Run tests
pytest tests/intent/ -v
# Check middleware config
curl http://localhost:8001/api/admin/intent-monitoring
classify(text, use_cache=False)Check cache performance:
curl http://localhost:8001/api/admin/intent-cache-metrics
Monitor middleware:
curl http://localhost:8001/api/admin/intent-monitoring
As of October 7, 2025 (GREAT-4F), the intent classifier achieves the following accuracy:
To maximize accuracy:
If classification seems wrong:
intent = await classifier.classify("What's my schedule?")
category = intent.category # TEMPORAL, STATUS, PRIORITY, etc.
confidence = intent.confidence # 0.0-1.0
action = intent.action # get_current_time, get_project_status, etc.
intent = await classifier.classify(
text="Create an issue",
context={"project": "piper-morgan"}
)
intent = await classifier.classify(
text="Real-time query",
use_cache=False
)
intent = await classifier.classify(user_input)
match intent.category:
case IntentCategory.TEMPORAL:
return await handle_temporal(intent)
case IntentCategory.STATUS:
return await handle_status(intent)
case IntentCategory.PRIORITY:
return await handle_priority(intent)
case IntentCategory.EXECUTION:
return await handle_execution(intent)
case _:
return await handle_unknown(intent)
User INPUT → Intent Classification (enforced here)
↓
Handler → Response Generation
↓
Piper OUTPUT → Personality Enhancement (separate concern)
cache_enabled: true in metrics responsepython scripts/check_intent_bypasses.py/api/admin/intent-cache-metrics/api/admin/intent-monitoring endpoint# Test intent classification directly
intent = await classifier.classify("What day is it?")
assert intent.category == IntentCategory.TEMPORAL
assert intent.confidence >= 0.8
# Test full HTTP flow
response = client.post("/api/v1/intent", json={"text": "What day is it?"})
assert response.status_code == 200
# Test caching behavior
start = time.time()
intent1 = await classifier.classify("What day is it?")
time1 = time.time() - start
start = time.time()
intent2 = await classifier.classify("What day is it?") # Should hit cache
time2 = time.time() - start
assert time2 < time1 # Cache should be faster
# In services/intent_service/cache.py
CACHE_TTL = 3600 # 1 hour
MAX_CACHE_SIZE = 1000 # entries
# In web/middleware/intent_enforcement.py
NL_ENDPOINTS = [...] # Natural language endpoints
EXEMPT_PATHS = [...] # Paths that don't need intent
Cache Performance:
Classification Accuracy:
Middleware Enforcement:
dev/2025/10/05/bypass-prevention-strategy.mdStatus: ✅ Production ready - All 13 categories implemented and validated
Last Validated: October 6, 2025 (GREAT-4E completion)