Embedding Detector
The embedding-detector policy compares message content with reference text.
The default local mode uses a bag-of-words cosine score. The external mode
can call an embedding endpoint when the installed CLI includes that support.
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
timeout_ms: 20
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 positioning
Fields
| Field | Type | Description | Default |
|---|---|---|---|
backend | local | external | Selects the backend. external makes HTTP calls only in a build with --features embedding-external. | local |
endpoint | string | External embedding URL. Only used for backend: external. | http://localhost:8080/embed |
model | string | External embedding model name. Only used for backend: external. | all-MiniLM-L6-v2 |
api_key | string | Optional bearer token sent to the external endpoint. | unset |
similarity_threshold | number | Minimum cosine similarity that triggers. | 0.70 |
timeout_ms | integer | External backend timeout in milliseconds. | 20 |
action | redact | block | block stops the request. redact returns a redact verdict for the gateway redaction path. | redact |
categories | array | More categories appended to the built-in sensitive categories. | [] |
categories[].label | string | Stable label for the category. | necessary |
categories[].reference_text | string | Reference text compared against each segment of the input. | necessary |
Built-in sensitive categories
When categories is empty, the detector starts with built-in references for:
- Social Security numbers
- credit cards / payment cards
- medical-record identifiers
- biometric data terms
- bank-account style identifiers
- prompt-injection language
- export-controlled technical data
External backend note
For backend: external, do these steps:
- Make sure that the installed CLI includes external embedding support.
- Give
endpointand, if necessary,modelandapi_key. - The local backend handles timeout or transport failures.
External errors use local scoring
An external timeout or transport error changes the request to the local bag-of-words check. Use this mode only when that result meets your policy.
Use cases
Local-only semantic screening
pack:
name: local-similarity-screening
version: 1.0.0
enabled: true
policies:
chain:
- embedding-detector
- audit-logger
policy:
embedding-detector:
backend: local
similarity_threshold: 0.8
action: block
Feature-gated external endpoint
pack:
name: external-embedding-screening
version: 1.0.0
enabled: true
policies:
chain:
- embedding-detector
policy:
embedding-detector:
backend: external
endpoint: https://embeddings.example.com/v1/embeddings
model: approved-embedding-model
timeout_ms: 200
similarity_threshold: 0.8
action: block
How it works
- The detector divides the input into sentence-like segments.
- In
localmode, it compares each segment with built-in and custom reference text. - In
externalmode it requests embeddings for the segment and each reference text, subject totimeout_ms. - If the external call fails or times out, the detector falls back to the local path.
- The first matching segment sets the policy cause code and verdict.
Best practices
- Use
categoriesto extend the built-in defaults. They do not replace the defaults. - Use higher thresholds (
0.8+) first to decrease false positives. - Reserve
externalmode for cases where you control the build flags and the endpoint. - Use
blockfor a deterministic outcome, not a generic redact verdict.
Next steps
- DLP Filter — Specified term and regex controls
- External Moderation — Third-party moderation providers
- Prompt Injection Detection — Dedicated prompt-injection policy
- Legal Privilege — Response-phase privilege controls