Testing Guide

How to test Highflame Shield integrations — monitor mode for non-blocking tests, test fixtures, signal assertions, debug/explain flags, and session tracking verification.

This guide covers how to write tests for applications that integrate Highflame Shield. The key principle is to test your guardrail logic without blocking test runs on policy decisions — unless you specifically want to test enforcement behavior.

Testing Strategies

There are three main approaches depending on what you want to test:

Approach
Use when

Monitor mode

Integration testing — observe decisions without blocking

Real service

End-to-end testing — verify full enforcement against live policies

Response inspection

Unit testing — assert on GuardResponse fields directly

Using Monitor Mode in Tests

Monitor mode lets the request through regardless of the policy decision. Use it to write tests that verify your application handles guardrail responses correctly without failing on enforcement:

import pytest
from highflame import Highflame, GuardRequest

@pytest.fixture
def client():
    return Highflame(api_key="hf_sk_test_...")

def test_guardrail_observes_prompt(client):
    resp = client.guard.evaluate(GuardRequest(
        content="What is the capital of France?",
        content_type="prompt",
        action="process_prompt",
        mode="monitor",  # Always allows, captures decision
    ))

    assert resp.decision == "allow"
    # actual_decision shows what would have been enforced
    # assert resp.actual_decision in ("allow", "deny")

Testing with a Test API Key

Use a dedicated test API key for your test suite. This isolates test traffic from production traffic in the Highflame observatory and ensures test policies don't affect production:

Testing Enforcement Behavior

To test that your application correctly handles a deny decision, evaluate a known-bad payload:

Testing Signal Detection

Test that your detector configuration fires on expected inputs by inspecting resp.signals:

Testing Shield Decorators (Python)

When testing code wrapped with @shield.prompt and similar decorators, use mode="monitor" to disable enforcement:

To test that your application raises on a blocked request, wrap the call and catch BlockedError:

Testing TypeScript Applications

Testing Session Tracking

To test cumulative risk logic, pass consistent session IDs across turns in a test:

Inspecting Debug Information

Use debug=True to get per-detector results in your test assertions:

Use explain=True to get policy trace information:

Using the Debug Resource

Verify your policies are loaded correctly before running tests:

Last updated