Tune Strictness and Reject

By the end of this guide, you'll know which of three settings controls what you're seeing, and how to set each one for an inline gateway or an offline review queue. The three are the request's strictness, the SDK's reject policy, and the scan profile's engine settings.

Before you start#

bash

# Python 3.11+
pip install "git+https://github.com/tendrl-inc-labs/surface-python"

# JavaScript
npm install github:tendrl-inc-labs/surface-js

# Go
go get github.com/tendrl-inc-labs/surface-go

Which setting does what#

Setting Where it lives What it changes
strictness Per request, in context, or as a default on the SDK client or guard How readily a judgment call on a payload becomes Review or Block
Reject policy Your SDK call, middleware or guard Which verdicts the SDK turns into an exception or a refused request. The verdict itself is unchanged
Engine settings The scan profile linked to the API key Which engines run, and which of their findings count toward the verdict

Only the profile is stored on the server. Strictness travels with each payload scan, and the reject policy runs in your process after the verdict comes back.

Strictness#

Three levels, for payload scans:

Strictness moves the judgment calls. It doesn't move what is dangerous on its face. A live credential sent outside, or a script from a bare IP piped to a shell, Blocks at every level. A document sent to an outside address the request never named is Allow at relaxed and Review at balanced and strict. The full action-by-level table is in Context fields.

Strictness also sets how far a prompt-injection match can move the verdict. At relaxed, a match on its own is held for Review and never Blocks. The effect by source is in Protect a chatbot.

File uploads take no context, so strictness has no effect on scan_file / scanFile / ScanFile.

Setting it#

Set a default once, and override it per call where you need to:

python

from surface import SurfaceClient, ToolGuard

client = SurfaceClient(strictness="strict")       # every scan_payload from this client
guard = ToolGuard(client, strictness="balanced")  # every call this guard screens
client.scan_payload(text, "note.txt", context={"strictness": "relaxed"})  # this call only
javascript

const client = new SurfaceClient({ strictness: "strict" });
const guard = new ToolGuard(client, { strictness: "balanced" });
await client.scanPayload(text, "note.txt", { context: { strictness: "relaxed" } });
go

client.Strictness = surface.StrictnessStrict
guard := &surface.ToolGuard{Client: client, Strictness: surface.StrictnessBalanced}
client.ScanPayload(ctx, []byte(text), "note.txt", &surface.ScanFileOptions{
    Context: &surface.ActionContext{Strictness: surface.StrictnessRelaxed},
})

The most specific setting wins. A strictness in the call's context comes first, then the guard's, then the client's. If none is set, Surface uses balanced. A client's default also covers scans made through the SDK middleware. An unknown value is refused: Python raises ValueError when you build the client or guard, JavaScript throws ValidationError, Go returns an error from the call, and the API answers 400.

What the SDK refuses by default#

A plain scan call returns the verdict and refuses nothing. Everything else depends on the entry point:

Entry point Default Change it with
scan_file, scan_payload (Python) · scanFile, scanPayload (JavaScript) · ScanFile, ScanBytes, ScanReader, ScanPayload (Go) Returns the verdict. Raises nothing for a verdict reject= (Python) · reject option (JavaScript) · ScanFileOptions.Reject (Go)
@scan decorator (Python) · withScan (JavaScript) · ScanFunc, ScanBytesFunc (Go) Same: nothing unless you pass reject The same reject setting
Request middleware: ScanMiddleware, scan_request (Python) · scanMiddleware, createSafeFetch (JavaScript) · ScanMiddleware, ScanHandlerFunc (Go) Rejects Block: a 403 from middleware, a thrown error from createSafeFetch. Passes Review through. Fails open if Surface can't answer reject / Reject, and fail_open / failOpen / FailOpen
ToolGuard.screen() · Go Screen Returns a Decision. Raises nothing for a verdict Your own branch
ToolGuard.wrap() · Go Check, Wrap Never runs on Block. Holds on Review (ToolNeedsReview, or *NeedsReviewError in Go). Fails closed on_review (Python), onReview (JavaScript): "hold", "allow", or a function that returns whether to run. Go OnReview: surface.ReviewHold, surface.ReviewAllow, or your own ReviewPolicy

When a scan call matches its reject list, it raises MaliciousFileError in Python and JavaScript, or returns a *surface.MaliciousFileError in Go. The scan result is on the error as .result (.Result in Go):

python

from surface import MaliciousFileError

try:
    surface.scan_file("upload.pdf", reject=["Block", "Review"])
except MaliciousFileError as e:
    log(e.result.safety_score.primary_threat)
go

_, err := client.ScanFile(ctx, "upload.pdf", &surface.ScanFileOptions{Reject: []string{"Block", "Review"}})
var rejected *surface.MaliciousFileError
if errors.As(err, &rejected) {
    log(rejected.Result.SafetyScore.PrimaryThreat)
}

Notes on reject:

Engine settings on the scan profile#

Each API key is linked to one scan profile, and every scan made with that key uses the profile's settings. The profile is the server-side place to quiet or tighten individual engines: Prompt Injection, Code Extraction, Sensitive Data, Tool Call Analysis, and Action screening, the engine that judges agent tool calls against context. Each can be switched off. All but Code Extraction also take a sensitivity, which decides which findings count:

Sensitivity Findings that count
strict (default) All of them
normal High and medium severity
permissive High severity only

For Action screening, the profile editor offers Strict and Permissive. Permissive counts only calls that would be blocked, so judgment calls such as a personal-mailbox recipient are no longer held for Review. Off removes action screening's findings and its effect on the verdict for every scan made with that profile. Through the API, set it with the other engines:

json

{
  "engine_config": {
    "action_screening": { "enabled": true, "sensitivity": "permissive" }
  }
}

If your users routinely write to customers on personal mailboxes, try personal_mail_expected: true in context first. Below strict, it allows a send to a personal address that user_request names, and leaves the rest of action screening in place. A live credential still Blocks.

Built-in profiles can't be modified, so engine changes go on a custom profile. Use one API key per profile, so each integration gets its own settings: one key for the live gateway, another for the review queue. Field details are in Scan profiles.

Choosing for an inline gateway or an offline queue#

Inline gateway. Surface sits in the request path: a chat endpoint, middleware in front of an agent, or ToolGuard before each tool runs. Each false positive stops a real person mid-task.

Offline review queue. Scans run in the background (uploaded files, a moderation backlog, an audit of past agent activity), and a person works through what's flagged. A Review costs someone a look, not a blocked user.

Inline gateway Offline review queue
strictness balanced strict
Act on Block. Confirm Review with the user Block and Review
Surface unavailable Decide per path: fail closed for tool calls Retry later
Timeout Short Default (60 s)