Error Reference

This page provides a complete reference for all error codes and exceptions you may encounter when using the AI Guard SDK and REST API.

HTTP Error Codes

Classification Endpoint (POST /classifications/v1)

HTTP StatusError CodeDescriptionCommon Cause
200β€”Successful classificationβ€”
400Bad RequestInvalid request body or parametersMalformed classifier description, missing required fields
401UnauthorizedAuthentication failedInvalid, expired, or missing bearer token
500Internal Server ErrorServer-side errorClassification engine failure
502Bad GatewayUpstream service unavailablescan-job-manager not reachable or classification profiles unavailable

Metrics Endpoint (POST /metric)

HTTP StatusError CodeDescriptionCommon Cause
200β€”Metric recorded successfullyβ€”
400Bad RequestMetrics not permitted or invalid requestMetrics disabled in config, or invalid meter name/attributes
401UnauthorizedAuthentication failedInvalid, expired, or missing bearer token

Health Endpoint (GET /health)

HTTP StatusDescription
200Service is healthy and ready

Error Response Format

All error responses use the following JSON structure:

{
  "code": 400,
  "message": "Description of the error"
}
FieldTypeDescription
codeintegerHTTP status code
messagestringHuman-readable error description

SDK Exceptions

The Python SDK maps HTTP error codes to Python exceptions:

HTTP StatusPython ExceptionDescription
400ValueErrorInvalid request β€” check the error message for details
401PermissionErrorAuthentication failed β€” verify your API key
500+RuntimeErrorServer error β€” check service logs
OtherRuntimeErrorUnexpected error

Exception Handling Pattern

from ai_guard import AIGuardClient
from ai_guard.api import (
    AIPlatform, ClassificationRequest, ClassifierDescriptionDefault,
    MetricsEvent, MetricsEventMeter,
)

client = AIGuardClient(
    "https://ai-guard.example.com:4443",
    token="your-api-key",
    agent_id="my-agent",
    platform=AIPlatform.AMAZON_BEDROCK,
)

# Classification errors
try:
    response = client.classify(ClassificationRequest(
        context={"actor": "user"},
        classifier_description=ClassifierDescriptionDefault(),
        text="test text",
    ))
except ValueError as e:
    # 400: Bad request β€” fix the request parameters
    print(f"Invalid request: {e}")
except PermissionError as e:
    # 401: Authentication failed β€” check your API key
    print(f"Auth failed: {e}")
except RuntimeError as e:
    # 500+: Server error β€” check service logs
    print(f"Server error: {e}")

# Metrics errors
try:
    client.metric(MetricsEvent(
        attributes={"new_session": "true"},
        meter=MetricsEventMeter(name="ai_guard.user", value="1"),
    ))
except ValueError as e:
    # 400: Metrics not enabled or invalid request
    print(f"Metrics error: {e}")
except PermissionError as e:
    # 401: Authentication failed
    print(f"Auth failed: {e}")
except RuntimeError as e:
    # Other error
    print(f"Error: {e}")

Client Construction Errors

ErrorCauseResolution
ValueError (pin_sha256)Invalid base64 encoding or digest not 32 bytesRe-extract the pin using openssl commands
ConnectionErrorCannot reach the AI Guard serviceVerify URL, port, and network connectivity

Common Error Scenarios

"Metrics not permitted"

HTTP 400 on POST /metric

The metrics section is not configured in the AI Guard service configuration file. Contact your administrator to enable metrics.

"Invalid or missing bearer token"

HTTP 401 on any authenticated endpoint

  • Verify the API key is correct
  • Ensure the key has Data Discovery scope
  • Check that the token validation endpoint is reachable (for OneTrust auth mode)

"Classification engine error"

HTTP 500 on POST /classifications/v1

An internal error occurred in the classification engine. Check the service logs (RUST_LOG=debug) for details.

"Upstream classification service unavailable"

HTTP 502 on POST /classifications/v1

The AI Guard service cannot reach the scan job manager for classification profiles. Verify:

  • JOB_EXECUTOR_BASE_URL is configured correctly
  • The scan-job-manager service is running and reachable

What's Next?

  • Troubleshooting β€” Step-by-step diagnostic guides
  • FAQ β€” Frequently asked questions