Embedding detector
embedding-detector compares each sentence of a request with reference texts, such as a description of your trade secrets, and flags a sentence that is similar enough. It has built-in references for identifiers, card data, health data, and injection, and you can add your own.
The control has three backends:
local, the default, compares meaning with the optional all-MiniLM-L6-v2 model. Install the model on the gateway host withverdictan models install embedding. The CLI does not bundle the model. While the model is not installed,localuses thelexicalcomparison. See verdictan models.lexicalcompares term frequencies. It finds shared words only. It does not recognize synonyms or meaning.externalgets embeddings from an endpoint that you operate. The endpoint receives the request text.
Configuration
pack:
name: embedding-detector-example
version: 1.0.0
enabled: true
policies:
chain:
- embedding-detector
policy:
embedding-detector:
backend: local
similarity_threshold: 0.75
action: block
categories:
- label: trade_secret
reference_text: >-
proprietary manufacturing process internal formula secret recipe
- label: competitive_intel
reference_text: >-
competitor pricing strategy acquisition target market positioningFields
| Field | Type | Default | Description |
|---|---|---|---|
backend | local, lexical, or external | local | local compares meaning with the optional local model, and uses lexical while the model is not installed. lexical compares term frequencies. external gets embeddings from endpoint. |
endpoint | string | http://localhost:8080/embed | Embeddings endpoint, for external only |
model | string | all-MiniLM-L6-v2 | Model name in the embeddings request, for external only |
api_key | string | Inline bearer token for the endpoint. A value with spaces or control characters is ignored. Use secret_key_ref instead. | |
secret_key_ref.env | string | Name of the gateway environment variable that holds the bearer token for the endpoint. api_key has priority when both are set. | |
on_external_error | lexical, allow, or block | lexical | Result when an external request fails or times out. lexical uses the lexical comparison. allow reports no detection. block makes the full input a detection, so action applies. |
similarity_threshold | number | 0.70 | Cosine similarity at which a sentence counts as a detection, from 0 to 1 |
timeout_ms | integer | 20 | Timeout of one embeddings request, from 1 to 60000. The local model does not use this limit. |
action | redact or block | redact | Verdict on a detection |
categories | list of objects | [] | Your own categories, added to the built-in ones |
categories[].label | string | Category name. Required. | |
categories[].reference_text | string | Text to compare with. Required. |
Phase and verdicts
| Item | Value |
|---|---|
| Stages | pre-request (default), pre-response |
| Request families | All |
| Verdicts | allow, redact, block |
| Reason codes | embedding.clean, embedding.pii, embedding.pan, embedding.phi, embedding.other |
Verify the comparison
Test with the first reference sentence and a greeting:
testing:
suites:
- name: embedding-detector
cases:
- name: blocks-reference-sentence
input: {messages: [{role: user, content: "proprietary manufacturing process internal formula secret recipe"}]}
expected: {verdict: block, reason_code: embedding.other}
- name: allows-greeting
input: {messages: [{role: user, content: "Hello, how are you?"}]}
expected: {verdict: allow, reason_code: ok}Run verdictan policy test --json. Both cases pass with the lexical comparison: the reference sentence shares every word and is blocked, and the greeting shares none. The scores of the local model are different. Run the test again after you install or remove the model.
Now test a paraphrase from your own application. Word overlap can miss it, so a low score does not prove that content is safe. The local model can find some paraphrases, but a low score also does not prove that content is safe.
Built-in categories
These always apply. categories adds to them. Each line gives the label, the reason code, and the reference text.
social_security_number,embedding.pii:social security number SSN taxpayer identificationcredit_card,embedding.pan:credit card number payment card PAN Visa Mastercardmedical_record,embedding.phi:medical record number MRN patient identifier health recordbiometric_data,embedding.phi:fingerprint biometric scan retinal iris facial recognitionfinancial_account,embedding.pii:bank account routing number IBAN swift wire transferprompt_injection,embedding.other:ignore previous instructions disregard system prompt overrideexport_controlled,embedding.other:ITAR EAR export controlled technical data defense article
Your own categories use embedding.other.
How it works
- The gateway joins the text of all request messages.
- The control splits it into sentences at
.,!,?, and line breaks, and skips sentences of three characters or fewer. - It scores each sentence against each category with cosine similarity.
- Local backend with the model installed: the model makes one embedding vector for the sentence and one for each reference.
- Lexical backend, and local backend without the model: lowercase, split into alphanumeric words, and compare word frequency vectors.
- External backend: one
POSTwith{"input": "<text>", "model": "<model>"}for the sentence and one for each reference. It readsdata[0].embeddingfrom each response. - A score at or above
similarity_thresholdis a detection. The first detection sets the reason code. - No detection:
allowwithembedding.clean. A detection:blockorredact, followingaction.
The details contain detection_count, first_kind, and first_confidence: high at 0.90 or more, medium at 0.80 or more, otherwise low.
Examples
Local backend, blocking detections. Install the model with verdictan models install embedding first:
policy:
embedding-detector:
backend: local
similarity_threshold: 0.8
action: blockExternal endpoint with a credential from the gateway environment:
policy:
embedding-detector:
backend: external
endpoint: https://embeddings.example.com/v1/embeddings
model: replace-with-embedding-model
secret_key_ref:
env: VERDICTAN_EMBEDDINGS_API_KEY
on_external_error: lexical
timeout_ms: 200
similarity_threshold: 0.8
action: blockLimits and failure behavior
- Lexical scoring counts shared words only. A sentence must share most of its words with a short reference to reach
0.70. - Without the local model,
backend: localuses lexical scoring. When the local model fails on one input, the control uses lexical scoring for that input./readyzshows the model state underoptional_models. - If an external request fails, times out, or returns a non-2xx status,
on_external_errorsets the result. The default is lexical scoring. The decision event does not say which backend scored. - The default
timeout_ms: 20is too short for most network endpoints. Raise it forexternal. - The external backend sends one request per sentence plus one per category (seven built-in plus yours). Long prompts cause many requests.
- The request text goes to the external endpoint. Use only an endpoint that your data policy allows.
secret_key_refaccepts onlyenv. Lint rejectsstore,scope, andkeychainin this field.- A block returns HTTP
400with error codecontent_policy_violation.redactstarts the shared PII redactor and does not remove the matching sentence. Useblockto stop the text.
Next steps
- DLP filter: exact terms and regular expressions.
- Prompt injection detection: the dedicated injection control.
- External moderation: classification by a moderation provider.