Skip to main content

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 with verdictan models install embedding. The CLI does not bundle the model. While the model is not installed, local uses the lexical comparison. See verdictan models.
  • lexical compares term frequencies. It finds shared words only. It does not recognize synonyms or meaning.
  • external gets embeddings from an endpoint that you operate. The endpoint receives the request text.

Configuration​

policy-config.yaml
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 positioning

Fields​

FieldTypeDefaultDescription
backendlocal, lexical, or externallocallocal 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.
endpointstringhttp://localhost:8080/embedEmbeddings endpoint, for external only
modelstringall-MiniLM-L6-v2Model name in the embeddings request, for external only
api_keystringInline bearer token for the endpoint. A value with spaces or control characters is ignored. Use secret_key_ref instead.
secret_key_ref.envstringName of the gateway environment variable that holds the bearer token for the endpoint. api_key has priority when both are set.
on_external_errorlexical, allow, or blocklexicalResult 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_thresholdnumber0.70Cosine similarity at which a sentence counts as a detection, from 0 to 1
timeout_msinteger20Timeout of one embeddings request, from 1 to 60000. The local model does not use this limit.
actionredact or blockredactVerdict on a detection
categorieslist of objects[]Your own categories, added to the built-in ones
categories[].labelstringCategory name. Required.
categories[].reference_textstringText to compare with. Required.

Phase and verdicts​

ItemValue
Stagespre-request (default), pre-response
Request familiesAll
Verdictsallow, redact, block
Reason codesembedding.clean, embedding.pii, embedding.pan, embedding.phi, embedding.other

Verify the comparison​

Test with the first reference sentence and a greeting:

Add to policy-config.yaml
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 identification
  • credit_card, embedding.pan: credit card number payment card PAN Visa Mastercard
  • medical_record, embedding.phi: medical record number MRN patient identifier health record
  • biometric_data, embedding.phi: fingerprint biometric scan retinal iris facial recognition
  • financial_account, embedding.pii: bank account routing number IBAN swift wire transfer
  • prompt_injection, embedding.other: ignore previous instructions disregard system prompt override
  • export_controlled, embedding.other: ITAR EAR export controlled technical data defense article

Your own categories use embedding.other.

How it works​

  1. The gateway joins the text of all request messages.
  2. The control splits it into sentences at ., !, ?, and line breaks, and skips sentences of three characters or fewer.
  3. It scores each sentence against each category with cosine similarity.
  4. Local backend with the model installed: the model makes one embedding vector for the sentence and one for each reference.
  5. Lexical backend, and local backend without the model: lowercase, split into alphanumeric words, and compare word frequency vectors.
  6. External backend: one POST with {"input": "<text>", "model": "<model>"} for the sentence and one for each reference. It reads data[0].embedding from each response.
  7. A score at or above similarity_threshold is a detection. The first detection sets the reason code.
  8. No detection: allow with embedding.clean. A detection: block or redact, following action.

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:

Inside policy-config.yaml
policy:
  embedding-detector:
    backend: local
    similarity_threshold: 0.8
    action: block

External endpoint with a credential from the gateway environment:

Inside policy-config.yaml
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: block

Limits 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: local uses lexical scoring. When the local model fails on one input, the control uses lexical scoring for that input. /readyz shows the model state under optional_models.
  • If an external request fails, times out, or returns a non-2xx status, on_external_error sets the result. The default is lexical scoring. The decision event does not say which backend scored.
  • The default timeout_ms: 20 is too short for most network endpoints. Raise it for external.
  • 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_ref accepts only env. Lint rejects store, scope, and keychain in this field.
  • A block returns HTTP 400 with error code content_policy_violation. redact starts the shared PII redactor and does not remove the matching sentence. Use block to stop the text.

Next steps​