Query Template Matching Flow

flowchart TD
    Start([User asks natural language question]):::io
    Normalize[Normalize question]:::process
    Similar[Calculate similarity to all templates]:::process
    Match{Template match found?}:::decision
    Select[Select best matching template]:::process
    Unsupported[Return unsupported query message]:::error
    Extract[Extract parameters from question]:::process
    Validate[Validate extracted parameters]:::validate
    Valid{Parameters valid?}:::decision
    Request[Request missing or invalid parameters]:::validate
    Calc[Calculate dynamic parameter values]:::process
    Substitute[Substitute parameters into SQL template]:::process
    Execute[Execute SQL query against database]:::process
    Success{Query successful?}:::decision
    LogError[Log error and return friendly message]:::error
    Format[Format results using response template]:::process
    End([Return formatted response to user]):::io

    Start --> Normalize --> Similar --> Match
    Match -->|No| Unsupported
    Match -->|Yes| Select --> Extract --> Validate --> Valid
    Valid -->|No| Request -->|loop back| Extract
    Valid -->|Yes| Calc --> Substitute --> Execute --> Success
    Success -->|No| LogError
    Success -->|Yes| Format --> End

    classDef io fill:#42a5f5,stroke:#0d47a1,stroke-width:2px,color:#fff,font-size:15px
    classDef process fill:#66bb6a,stroke:#1b5e20,stroke-width:2px,color:#fff,font-size:15px
    classDef decision fill:#ffd54f,stroke:#f57f17,stroke-width:2px,color:#333,font-size:15px,font-weight:bold
    classDef validate fill:#ff9800,stroke:#e65100,stroke-width:2px,color:#fff,font-size:15px
    classDef error fill:#ef5350,stroke:#b71c1c,stroke-width:2px,color:#fff,font-size:15px

    linkStyle default stroke:#777,stroke-width:2px,font-size:14px
            
Step Color Key
Input / output
Processing steps
Decision points
Validation steps
Error handling

Step Details

Hover a step to see how it works.