feat: add semantic fallback scanner for scan stage#10
Open
Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Open
feat: add semantic fallback scanner for scan stage#10Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Conversation
This was referenced Mar 19, 2026
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.
Semantic Fallback Scanner - Scan Stage (v1)
What this PR adds
This implements the semantic fallback layer in the scan stage of the PDP pipeline, as defined in the v0.2 architecture:
The lexical scanner (Aho-Corasick) catches known attack patterns via exact/regex matching. The semantic scanner catches paraphrased, novel, and obfuscated injections that lexical scanning misses, by comparing normalised inputs against a pre-computed library of attack embeddings using cosine similarity.
Architecture alignment
PROCEEDSHORT_CIRCUIT_BLOCKon high-confidence matchesrisk_score+semantic_hitslist for the risk aggregator (signal-producer pattern)How it works
block_threshold, returnsSHORT_CIRCUIT_BLOCK. Otherwise returnsPROCEEDwith the risk score for downstream aggregationPluggable embedding backends
sentence-transformerall-MiniLM-L6-v2(384d)sentence-transformers, PyTorchtfidfscikit-learnThe backend is swappable at init:
Attack pattern library
49 patterns across 6 categories, curated from PINT benchmark, Open-Prompt-Injection, HackAPrompt, and manual red-teaming:
instruction_overridecontext_manipulationdata_exfiltrationtool_abuserole_hijackencoding_evasionThe library is extensible — add patterns by appending to the relevant list in
attack_library.py.Configuration
Files
Tests
Test coverage includes:
SHORT_CIRCUIT_BLOCKon exact matchesNext steps