Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Protectai Llm guard REST API Scanning Endpoints

From Leeroopedia
Knowledge Sources
Domains API_Design, Web_Development, Security
Last Updated 2026-02-14 12:00 GMT

Overview

A REST API endpoint pattern that exposes LLM Guard scanning functionality via HTTP POST endpoints for both sequential (analyze) and parallel (scan) execution modes.

Description

The REST API scanning endpoints provide two modes for both prompt and output scanning:

  • Analyze endpoints (/analyze/prompt, /analyze/output): Run scanners sequentially, return sanitized text along with validity and risk scores. Support fail-fast mode.
  • Scan endpoints (/scan/prompt, /scan/output): Run scanners in parallel using asyncio, return only validity and risk scores without sanitizing. Faster for validation-only use cases.

Both modes support scanner suppression (disabling specific scanners per request), authentication, rate limiting, and configurable timeouts.

Usage

Use this principle when integrating LLM Guard into microservice architectures where the scanning service runs as a separate process. The analyze endpoints are for pipelines that need sanitized text; the scan endpoints are for fast validation-only checks.

Theoretical Basis

# Pseudocode for analyze vs scan endpoints
# Analyze: sequential, returns sanitized text
@post("/analyze/prompt")
async def analyze_prompt(request):
    sanitized, valid, scores = scan_prompt(scanners, request.prompt, fail_fast)
    return {"sanitized_prompt": sanitized, "is_valid": all(valid), "scanners": scores}

# Scan: parallel, returns only scores
@post("/scan/prompt")
async def scan_prompt_parallel(request):
    tasks = [async_scan(scanner, request.prompt) for scanner in scanners]
    results = await asyncio.gather(*tasks)
    return {"is_valid": all_valid(results), "scanners": aggregate_scores(results)}

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment