NLP parser: add confidence scoring and a clarification fallback - #408
Merged
Abidoyesimze merged 1 commit intoAug 30, 2026
Merged
Conversation
…owealth#401) Every parsed Intent now carries a confidence score (1 for a clean regex match, a fixed heuristic for a Claude classification, 0 for unknown). When a message names two or more competing actions without a confident single match (e.g. "should I deposit or withdraw?"), the regex parser returns a new 'clarification' intent with a prompt built via src/nlp/responses.ts instead of guessing at the nearest pattern or falling straight through to unknown. The threshold is configurable via NLP_CONFIDENCE_THRESHOLD (config.nlp.confidenceThreshold, default 0.6). WhatsApp and Telegram handlers render the clarification prompt directly.
|
@sammajayi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Intentnow carries aconfidencescore in[0, 1]:1for a clean deterministic regex match, a fixed heuristic (0.85) for a valid Claude classification,0forunknown.'clarification'intent: when a message names two or more competing actions without a confident single match (e.g. "should I deposit or withdraw?"), the regex parser returns a clarification prompt instead of guessing the nearest pattern or falling straight through tounknown. The prompt is built viasrc/nlp/responses.ts's newclarification()generator.config.nlp.confidenceThreshold(envNLP_CONFIDENCE_THRESHOLD, default0.6) insrc/config/env.ts.case 'clarification'), instead of it silently falling into the generic "I didn't understand that" reply via theirdefaultcase."deposit") are left unchanged — they still escalate to Claude / fall tounknownas before, since there's nothing to disambiguate between.Closes #401.
Test plan
tests/unit/nlp/parser.test.ts: confidence on clean matches, clarification triggering for 2-way and 3-way ambiguous phrasings, confidence scaling with more competing actions, non-triggering for single-signal/no-signal input, andresponses.clarification()wording for 1/2/3+ labels.npm test) passes: 112 suites / 1539 tests.