Skip to content

NLP parser: add confidence scoring and a clarification fallback - #408

Merged
Abidoyesimze merged 1 commit into
Neurowealth:mainfrom
sammajayi:feat/nlp-confidence-clarification-401
Aug 30, 2026
Merged

NLP parser: add confidence scoring and a clarification fallback#408
Abidoyesimze merged 1 commit into
Neurowealth:mainfrom
sammajayi:feat/nlp-confidence-clarification-401

Conversation

@sammajayi

Copy link
Copy Markdown
Contributor

Summary

  • Every parsed Intent now carries a confidence score in [0, 1]: 1 for a clean deterministic regex match, a fixed heuristic (0.85) for a valid Claude classification, 0 for unknown.
  • Added a new '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 to unknown. The prompt is built via src/nlp/responses.ts's new clarification() generator.
  • The trigger threshold is configurable: config.nlp.confidenceThreshold (env NLP_CONFIDENCE_THRESHOLD, default 0.6) in src/config/env.ts.
  • WhatsApp and Telegram handlers render the clarification prompt directly (case 'clarification'), instead of it silently falling into the generic "I didn't understand that" reply via their default case.
  • Single-topic, incomplete messages (e.g. bare "deposit") are left unchanged — they still escalate to Claude / fall to unknown as before, since there's nothing to disambiguate between.

Closes #401.

Test plan

  • New 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, and responses.clarification() wording for 1/2/3+ labels.
  • Existing WhatsApp/Telegram handler test suites pass unchanged.
  • Full test suite (npm test) passes: 112 suites / 1539 tests.

…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.
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Abidoyesimze
Abidoyesimze merged commit 1be5d44 into Neurowealth:main Aug 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NLP parser: add confidence scoring and a clarification fallback

2 participants