Skip to content

SIFA V4 — Reply Classifier (fast-path)

A high-performance classification system that handles deterministic youth responses in the SIFA coaching onboarding flow without requiring LLM calls. This workflow sits between user input processing and the AI agent, routing simple responses (like "yes/no" answers) through pre-written templates while passing complex queries to the full AI system.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

How It Works

  1. Input Processing: Receives youth reply data including phone number, query text, current onboarding step, and chat history
  2. Safety Pre-checks: Scans for welfare/safety signals, scam concerns, or loan requests that need special handling
  3. Step-specific Classification: Uses the current onboarding step to determine appropriate response logic
  4. Intent Detection: Analyzes user input for positive/negative responses, acknowledgments, or specific keywords
  5. Response Generation: Either produces a verbatim SIFA template response or routes to the LLM for generative handling
  6. Step Advancement: Updates the user's onboarding progress when appropriate
  7. Output Formatting: Structures the response with proper formatting (plain text vs interactive buttons)

The system is designed to be conservative — when in doubt, it routes to the LLM rather than risk inappropriate automated responses.

Mermaid Diagram

graph TD
    A[classifyYouthReply] --> B{handledBy code?}
    B -->|Yes| C{code: advance?}
    B -->|No| F[llm: handoff stub]
    C -->|Yes| D[updateStep code path]
    C -->|No| E[code: setOutput]
    D --> E
    F --> G[End - LLM Path]
    E --> H[End - Code Path]

Trigger

This workflow is designed to be executed by another workflow (sub-workflow pattern). It expects to receive: - Phone number of the youth - Query text from the user - Current onboarding step - User record with chat history - Built prompt data from the parent workflow

Nodes Used

Node Type Node Name Purpose
Code classifyYouthReply Main classification logic that analyzes user input and determines response strategy
If handledBy code? Routes flow based on whether the response can be handled deterministically
If code: advance? Checks if the user's onboarding step should be advanced
Postgres updateStep (code path) Updates user's onboarding progress and CEA alert status in database
Set code: setOutput Formats the final response for code-handled cases
Set llm: handoff (stub) Prepares data for LLM processing (stub for testing)

External Services & Credentials Required

  • PostgreSQL Database: Stores youth entrepreneur records and onboarding progress
    • Credential: sifaV4Dev
    • Required permissions: UPDATE on v4_youthEntrepreneurs table

Environment Variables

No explicit environment variables are used in this workflow. Configuration is handled through: - Database connection credentials - Hard-coded constants in the classification logic (toll-free number, response templates)

Data Flow

Input: - phoneNumber: Youth's phone number - query: User's text message - currentStep: Current onboarding step - firstName: User's first name - chat: Recent conversation history

Output (Code Path): - output: Verbatim SIFA response text - outputType: 'plain' or 'interactive' - outputOptions: Array of button options (if interactive) - handledBy: 'code' - classification: Intent classification for logging

Output (LLM Path): - handledBy: 'llm' - classification: Reason for LLM routing - note: Instructions for parent workflow

Error Handling

The workflow uses a conservative error handling approach: - Unknown steps: Route to LLM rather than fail - Ambiguous input: Route to LLM for nuanced handling - Safety signals: Welfare concerns are flagged but routed to LLM for appropriate response - Database errors: Would propagate to parent workflow for handling

Known Limitations

  • Currently inactive (workflow status shows "active": false)
  • LLM handoff is implemented as a stub for testing purposes
  • Requires integration with parent workflow for full functionality
  • Hard-coded response templates may need updates as SIFA's voice evolves
  • Conservative routing may result in unnecessary LLM calls for some deterministic cases

This workflow is part of the larger SIFA V4 onboarding system and should be connected to: - Main onboarding workflow that calls this as a sub-workflow - AI Agent workflow for handling LLM-routed responses - User record management workflows

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance
  2. Configure Database:
    • Set up PostgreSQL connection with credential name sifaV4Dev
    • Ensure access to v4_youthEntrepreneurs table
  3. Parent Workflow Integration:
    • Wire this as a sub-workflow after buildOnboardingPrompt
    • Connect the LLM path output back to your AI Agent node
    • Ensure proper data passing from trigger and user record nodes
  4. Testing:
    • Use the webhook tester mode by passing data directly to the first node
    • Test various user inputs across different onboarding steps
  5. Activation: Set "active": true when ready for production use
  6. Monitoring: Monitor the classification output for performance analytics and potential improvements