Testing your integration

Use offline SDK mocks to test application logic, or harmless test inputs to check policies, webhooks and delivery end to end. The scenario builder sets explicit outcomes for individual category instances, independent of your project policy. Real test uploads count towards usage, apart from declared person and face detection results; mocks do not.

Unit tests without the network

For tests that shouldn't call CalmLens at all, use your SDK's mock client to simulate each moderation status:

import { MockCalmLensServerClient, createMockApiKey } from "calmlens/testing";

const client = new MockCalmLensServerClient({
  apiKey: createMockApiKey(),
  projectId: "proj_8fK2mQx7Lp4NvB3tRz9Y",
  mockOptions: { moderate: () => "blocked" },
});

const result = await client.assets.classify({ name: "text", content: { plainText: "anything", type: "text/plain" } });
// result.classification.moderation.status === "blocked"

Test real moderation

A test input is a harmless image or text code that tells CalmLens which findings and outcome to report, so you can check policies, webhooks and delivery with real uploads. Test inputs are off by default: turn on Test inputs in the projects you test with, such as a staging project. Signed-in users see their selected project's codes and images below, and the test inputs in Try your policy are already authenticated for that project.

Regional outcomes

Set regional delivery outcomes. The strongest instance outcome still applies everywhere.

People and faces

What person and face detection report for the test image, in place of detecting anyone.

Up to 32, placed side by side; adjust each box below.
Up to 32, placed side by side; adjust each box below.
Allowed
Sexual0.01Allowed
Violence0.01Allowed
Self-harm0.01Allowed
Harassment0.01Allowed
Hate0.01Allowed
Criminal0.01Allowed
Personal info0.01Allowed
Profanity0.01Allowed

Select a project to generate authenticated text and image samples.

How test inputs behave

  • Images are square PNGs, at most 512 pixels a side, that encode the scenario as a grid of light and dark tiles inside a black-and-white border. The tiles' colours hint at the categories involved (grey when there are none) but don't decide the outcome, and larger scenarios use more, smaller tiles. The grid survives conversion to JPEG or WebP and resizing, so long as the image stays square and no larger than 512 pixels; cropping, rotating or drawing over it breaks the grid. The image must be the whole upload: one that shows anything else on or around the grid, apart from a plain border of one colour, is moderated as ordinary content. In video and in any sampled frame of an animated image, the same images add their findings to the media's own moderation.
  • Text codes carry the same scenario as the image. Submit the code as the whole text, apart from surrounding whitespace. A PDF or Word document whose only text is the code also counts, even where the code wraps across lines. Text with anything besides the code is moderated as ordinary content, and so is a code in a spreadsheet's cells or a presentation's slides. A test image on a slide is still recognised as one of the presentation's images. Text read from an image, by OCR or from a QR code, is never a test input.
  • Scores default to 95% for categories with instances and 1% for other assessed categories.

Both forms are signed with the project's test input key, which covers the whole scenario, including scores and unassessed categories. If test inputs are turned off, or the input was made for another project, was altered or is damaged, CalmLens moderates it as ordinary content.

Build your own scenario

Enable a category and add one or more instances. Give each instance an explicit limit, age-restrict or block action. To leave a category undetected, turn it off or remove all its instances. Qualifier chips describe that instance; they do not change its chosen action. The strongest instance action wins within a category and across the scenario.

The preview shows the outcome for each of the eight categories. It runs in your browser, doesn't count towards usage, and is the same for the PNG and the text code, because the actions you choose replace your project's policy.

Each scenario supports up to 128 instances and 64 qualifiers per instance, as long as the encoded input stays within its size limit. An empty scenario is allowed. When a scenario sets explicit actions and the test input is the whole upload, CalmLens skips your policy, jurisdiction rules and hash lists and uses those actions, plus any regional outcomes the scenario sets, as the decision. moderation.categories holds each category's resulting action, moderation.automatedStatus the resulting status and moderation.regions the regional outcomes.

To test policy rules themselves, generate test inputs in code from scenarios with no instance action values. Those use normal category, allowance, restriction and jurisdiction evaluation. Don't mix explicit and omitted actions within one scenario. Programmatic inputs can also override scores or mark categories unassessed.

Sample presets

The builder starts from editable presets with explicit instance actions. Every SDK's test input helpers take the same instance format and include these presets without the actions, so your policy decides them: under a policy that allows sexual text, for example, the adult text preset is allowed. Add an action to an instance when you want a fixed outcome.

SampleSetup and expected result
Limited contentAn instance explicitly set to limit produces limited. The CDN serves it normally; your app reduces its reach.
Age-restricted contentThe image and text code both produce age-restricted. Request without age confirmation for 403 viewer/age-confirmation-required, then with viewerClaims.ageConfirmed: true to receive it.
Region-blocked in GermanyNo category instances are enabled, and Germany has an explicit Block outcome. Request with viewerClaims.region: "DE" for 403 asset/not-available, and "US" for successful delivery. Age confirmation never overrides the block. See Set explicit regional outcomes.

To test CDN delivery, keep the sample's content after moderation, and use a public asset or provide the required private-asset access.

Find your test input key

Test inputs made outside the portal, such as with calmlens trigger or the SDK helpers, need the project's secret test input key: 32 hexadecimal characters, available in Project settings to members who can read its settings. Uploading content, including with an API key, never reveals it. The calmlens trigger command takes it with --test-key or the CALMLENS_TEST_INPUT_KEY environment variable.

Generate test inputs in code

Every SDK generates text codes and media phrases for a scenario from your project's test input key, without contacting CalmLens, so tests against a real project can create the inputs they need. Each SDK's testing guide describes its helpers.

import { generateTestTextCode, TEST_INPUT_PRESETS } from "calmlens/test-inputs";
import { generateMediaTestCode } from "calmlens/testing";

const testInputKey = process.env.CALMLENS_TEST_INPUT_KEY ?? "";

// Choose each instance's outcome: the strongest action wins
const text = await generateTestTextCode(
  {
    instances: [
      { category: "harassment", qualifiers: ["harassment-abuse", "harassment-documentary"], action: "limit" },
      { category: "harassment", qualifiers: ["harassment-threat"], action: "limit" },
      { category: "harassment", qualifiers: ["harassment-abuse"], action: "block" },
    ],
  },
  testInputKey,
);

// Regional delivery outcomes without category findings
const regional = await generateTestTextCode(TEST_INPUT_PRESETS.regionalDelivery, testInputKey);

// A phrase to read aloud or show in a video
const phrase = await generateMediaTestCode("violence", testInputKey);

Every SDK also paints the test image for a scenario. The Python, Go, Rust, Ruby, Java and PHP SDKs return PNG bytes ready to upload alongside the RGBA pixels; the JavaScript SDK returns the RGBA pixels (paintTestImage from calmlens/test-inputs) for you to encode.

Keep the key secret

Each sample contains a 128-bit HMAC tag bound to the project and complete input, rather than the key itself, so a sample cannot reveal the key or authenticate altered findings. Anyone with a valid sample can still reuse it in that project while test inputs are enabled. It only decides an upload that is the sample itself.

If a sample or the key reaches someone who shouldn't have it, rotate the key in Project settings: samples made with the old key are then moderated normally. To moderate test inputs normally instead, turn off Test inputs.

Set explicit regional outcomes

Scenarios can specify regional limit, age-restrict or block outcomes independently of category qualifiers, and both the image and text code carry them. The Regional delivery outcomes preset starts with no detected categories and sets Germany to Block, the United Kingdom to Age-restrict and France to Limit. Start from it or Clean content to test regional delivery independently of category rules.

  1. If the scenario sets an EU outcome, opt into the EU under Jurisdictions served before classifying the input. EU outcomes don't apply until the project opts in, although the preview shows them. The other jurisdictions always apply.
  2. Upload the generated PNG unchanged, or submit its text code, keeping its content after moderation.
  3. Request it with viewerClaims.region: "DE" to test the block, "GB" to test age restriction, "FR" to test limited delivery, and "US" as a control. In the UK, viewerClaims.ageConfirmed: false refuses delivery and true permits it unless another rule blocks it. Limit permits delivery; your app handles reduced reach.

Regional outcomes only make delivery stricter: countries without one keep the base decision, a global block still blocks everywhere, and existing jurisdiction restrictions can't be softened. Region-specific purge isn't offered because deleting the asset would affect every country.

The resulting moderation.regions entries identify these synthetic restrictions with rule: "test-input". See Jurisdiction rules for region defaults and proxy forwarding.

Test person and face detection

People and facesPreview

A test image can declare what person and face detection report for it, so you can test how your app handles people, faces and age ranges without photos of real people. Add detections to the scenario, or build it under People and faces in the builder:

{
  "instances": [],
  "detections": {
    "people": [{ "box": [2500, 1500, 5000, 8500] }],
    "faces": [{ "box": [3500, 2000, 3000, 3500], "confidence": 97, "age": "minor" }]
  }
}
FieldValues
people, facesUp to 32 entries each, or "unavailable" to report the feature as not-evaluated. A list left out, or empty, finds nobody.
box[left, top, width, height] as whole numbers from 0 to 10000, in hundredths of a percent of the image's width and height. The box must lie inside the image. Results report it as fractions from 0 to 1.
confidenceOptional, a whole number from 0 to 100. Defaults to 99.
ageFaces only, optional: "adult" (25–35), "minor" (12–16) or { "low": 40, "high": 48 } with whole years from 0 to 120. Defaults to "adult".

The SDK presets oneFace, noFace, adultFace, minorFace and group (named in each SDK's own style) cover common cases.

When CalmLens recognises the test image, it reports exactly these results instead of running detection: only the features the upload turned on, with ageRange only when it set ageEstimation: true. They aren't billed. redact.faces blurs the declared face boxes. Detections only come from a still test image; an animated image is always run through detection, and a text code never declares people or faces.

Test results are declared, not detected. Assets decided by a test input, one that was the whole upload, have classification.testInput: true, as do the asset snapshots in their events and webhooks. Findings a test input adds to audio, video or an animation don't set it. Never let a test input's age ranges, or any other test result, feed real age gating or other real decisions: check classification.testInput and ignore those results outside your tests.

Audio and video test codes

AudioPreview · VideoPreview

Generate a media phrase with your SDK's test input helpers. Read a code clearly in a recording, or show it as large, high-contrast text in a video for at least two seconds. Leave the whole phrase visible, including “Calm Lens test” and “end test”. For policies without allowances or restrictions, CalmLens moderates the media in sections and checks each one for the complete phrase, so detection depends on readable text and clear speech. For policies with them, as every built-in policy has, video is sampled once per second, and the phrase is found by reading on-screen text and transcribing speech. A phrase that crosses a section boundary can be missed despite the one-second overlap.

Media phrases contain 32 tag characters followed by the category. The spoken form spells each hexadecimal character using zero through nine and alpha, bravo, charlie, delta, echo and foxtrot. A visible overlay can use the compact hexadecimal tag. Use the complete generated phrase; the tag is different for each category and is not the project key.

Pass one of these categories to the helper: sexual, violence, self-harm, harassment, hate, criminal-activity, personal-information, profanity or violence.graphic. The phrase spells it with spaces in place of - and ., such as self harm or violence graphic. A phrase from another project is moderated normally.

Test images work in video with every policy. Show the image for at least two seconds, filling the picture or centred on a plain background, such as letterboxing; video compression, scaling and stretching don't break it. Very large scenarios use tiles too small to survive video, so keep video scenarios to a few instances. In audio, video and animated images, a test image or media phrase adds its findings to the moderation of the media, which still sees every frame and all speech, and your policy decides the result: explicit instance actions don't apply, and the asset isn't marked as a test input. Media phrases always use normal policy decisions, including limiting, age restriction, blocking or purging. A phrase is decided as the audio or video it stands for, even when it is found in on-screen text or speech, so sexual and violence.graphic phrases follow your policy's rules for images and video rather than its rules for text. Neither kind of test input simulates a processing failure. Test invalid media separately by uploading a corrupt file with an audio/video MIME type and checking that its classification.status ends as failed.

Last updated

Signing in

Signing out

Cookies on CalmLens

We use essential cookies for sign-in and security. With your permission, functional cookies remember your preferences and Google Analytics measures website use and signups. Optional ad measurement cookies link Google ad clicks to signups. Personalised advertising stays off. Manage cookies