feat: add NADIRCLAW_CLASSIFIER_STRIP_PATTERNS env var for classifier input cleaning - #77
Conversation
…input cleaning Agent frameworks (OpenClaw, Claude Code, NanoBot, Hermes, etc.) often wrap the human's actual prompt in a structured envelope - metadata blocks, memory context, system notes - that does not reflect the complexity of the request. The classifier sees JSON schemas, memory dumps, and tool definitions, inflating the score even for trivial requests like "hello". Changes: - settings.py: new CLASSIFIER_STRIP_PATTERNS property (env var, default empty = off) - server.py: _strip_classifier_input() function + call sites in _smart_route_full, /v1/classify, and /v1/classify/batch - Invalid regex logs a warning and is silently ignored (no crash) - Zero overhead when unset: regex is None, function is a no-op
|
Thanks for this — the shape is right: opt-in, default-off, classifier-only (LLM still sees the full prompt), and fail-safe on invalid regex. The motivation (agent envelopes inflating the complexity score) is real and matches how OpenClaw/Claude Code wrap prompts. A few notes from an automated triage review before a maintainer takes it: Substantive
Minor
None of these are blockers; (1) is the one I'd want before merge. Nice, self-contained change otherwise. 🤖 Automated triage review (claude code). A maintainer will make the merge call. |
Addresses the one pre-merge blocker from review: an over-broad NADIRCLAW_CLASSIFIER_STRIP_PATTERNS could consume the entire prompt, leaving the classifier an empty string and silently routing everything to the cheapest tier. _strip_classifier_input now returns the original text when stripping empties it. Adds tests/test_classifier_strip.py covering the contract: unset => identity, pattern strips envelope (incl. DOTALL across newlines), invalid regex => no-op + warning, and the over-broad => fall-back-to-original guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Pushed the pre-merge blocker fix and tests directly to this branch (
I approved the workflow run so CI validates this on the fork. The two minor notes from the prior review (one-shot init via a sentinel instead of re-reading the env when unset; the Once CI is green this is good to merge from my side. Thanks for the clean, self-contained change @BunpGhost. 🤖 Automated triage (claude code). A maintainer makes the final merge call. |
|
Thanks for the review and for applying the fixes directly, @doramirdor. The empty-strip guard and tests were solid catches. I'll wait for the next release to pull this in. Appreciate the help! |
Summary
Adds a new env var
NADIRCLAW_CLASSIFIER_STRIP_PATTERNSthat strips regex-matched blocks from user prompts before complexity classification. The LLM still sees the full, unmodified prompt.Motivation
Agent frameworks (OpenClaw, Claude Code, NanoBot, Hermes, etc.) often wrap the human's actual prompt in a structured envelope - metadata blocks, memory context, system notes, tool call dumps. Without stripping, the classifier sees predominantly JSON schemas and technical text, inflating the complexity score even for trivial requests.
Changes
CLASSIFIER_STRIP_PATTERNSproperty (default empty string = off)_strip_classifier_input()function compiled lazily from the env var, wired into 3 call sites:_smart_route_full()(the main routing path)/v1/classify/v1/classify/batchDesign
None, function is a no-opExample env var