AICredits logo
Features

Guardrails

Configure PII masking, blocked keywords, and response validation to keep your AI application safe and compliant.

Use this page with an AI assistant

Opens a new chat with this docs URL and the correct AICredits base URLs.

Guardrails are a set of server-side controls that run on every request before it reaches the LLM provider. They protect your application from sensitive data leakage, policy violations, and malformed responses.

Overview

FeatureWhat it doesStatus
PII MaskingDetects and masks sensitive data before sending to LLMAvailable
Blocked KeywordsRejects requests containing prohibited termsAvailable
Response HealingRepairs malformed JSON responses automaticallyAvailable

All guardrails run on the server — no client changes needed.

PII Masking

When enabled, PII masking scans the request content and replaces sensitive data with anonymised placeholders before sending to the LLM provider. The LLM never sees the real values.

What gets masked:

CategoryExamplesPlaceholder
Email addresses[email protected][EMAIL]
Phone numbers+91-9876543210[PHONE]
Aadhaar numbers1234 5678 9012[AADHAAR]
PAN numbersABCDE1234F[PAN]
Credit card numbers4111 1111 1111 1111[CREDIT_CARD]
Bank account numbers9–18 digit sequences[BANK_ACCOUNT]
Passport numbersStandard formats[PASSPORT]

PII masking is transparent to your application — the request proceeds normally, and the LLM responds as if it received the original text. Only sensitive values are replaced; all other content is unchanged.

Enabling PII Masking

PII masking is toggled via a server-side environment variable. Contact support or check your account settings to enable it for your organization. No API changes are required on the client side.

Blocked Keywords

You can configure a list of prohibited keywords or phrases. Any request containing a blocked keyword is rejected immediately with a 400 error — it never reaches the LLM provider.

Blocked keyword error response
{
  "error": {
    "message": "Request blocked: contains prohibited content",
    "type": "invalid_request_error",
    "code": 400
  }
}

Blocked keyword matching is case-insensitive and checks all message content (system, user, and assistant turns).

Response Healing

When you request structured JSON output ("response_format": {"type": "json_object"}), LLMs occasionally return malformed JSON — truncated responses, extra text around the JSON object, or minor formatting issues. Response healing automatically detects and repairs these cases.

What response healing fixes:

  • Truncated JSON (missing closing } or ])
  • Extra preamble or postamble text (e.g., "Sure! Here's the JSON: {...}")
  • Minor formatting issues
Requesting JSON output (healing is automatic)
response = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[
        {"role": "system", "content": "Return a JSON object with name and age."},
        {"role": "user", "content": "John Doe, 30 years old"},
    ],
    response_format={"type": "json_object"},
)

# If the provider returned malformed JSON, it's healed transparently
import json
data = json.loads(response.choices[0].message.content)

Response healing has limits. It handles minor issues reliably, but cannot repair severely truncated responses (e.g., a 10-token response for a 2,000-token JSON schema). Set max_tokens high enough to allow the full response.

Data Retention

For compliance, you can configure your account's data retention policy. With metadata_only retention, request and response content is never stored — only metadata (model, token counts, cost, timestamp) is retained for billing and usage analytics.

Contact support to configure your retention policy, or check your Profile settings.

On this page