Custom Content Policies

Create and manage custom content policies to enforce brand guidelines, compliance requirements, and industry-specific restrictions on top of LockLLM's built-in safety categories.

Link to section: What are Custom Content Policies?What are Custom Content Policies?

Custom content policies let you define your own content restrictions on top of LockLLM's built-in safety categories. While the built-in categories protect against universal threats like violent content, hate speech, and privacy violations, custom policies let you enforce rules specific to your business, industry, or brand.

Key benefits:

  • Enforce brand-specific guidelines, compliance requirements, and industry restrictions
  • Each policy supports descriptions up to 10,000 characters for precise definitions
  • Enable or disable individual policies without deleting them
  • Works in both scan endpoint and proxy mode
  • Share policies across your team with organization support
  • All policies checked in a single scan - no additional latency per policy
  • Combine with core threat detection for comprehensive protection

Link to section: Built-in Safety CategoriesBuilt-in Safety Categories

LockLLM includes built-in safety categories that are always checked when using combined or policy_only scan modes. These cover:

  • Violent crimes and threats
  • Non-violent criminal activity
  • Sex-related crimes
  • Child exploitation
  • Defamation
  • Specialized professional advice
  • Privacy violations
  • Intellectual property concerns
  • Weapons and dangerous materials
  • Hate speech and discrimination
  • Suicide and self-harm
  • Sexual content
  • Election interference
  • Code execution abuse

Custom policies extend these built-in categories with your own rules. Both built-in and custom categories are evaluated together in a single pass.

Link to section: Creating a PolicyCreating a Policy

Link to section: Step 1: Navigate to PoliciesStep 1: Navigate to Policies

  1. Sign in to your LockLLM dashboard
  2. Go to Settings > Custom Policies (or visit lockllm.com/policies)

Link to section: Step 2: Create a New PolicyStep 2: Create a New Policy

  1. Click Create Policy
  2. Enter a policy name - a short, descriptive label (e.g., "No Medical Advice")
  3. Write a policy description - a detailed definition of what should be flagged or blocked (up to 10,000 characters)
  4. Click Save

Link to section: Step 3: Enable in Your RequestsStep 3: Enable in Your Requests

Set the scan mode to combined (default) or policy_only to activate custom policy checking:

const openai = new OpenAI({
  apiKey: process.env.LOCKLLM_API_KEY,
  baseURL: 'https://api.lockllm.com/v1/proxy/openai',
  defaultHeaders: {
    'X-LockLLM-Scan-Mode': 'combined',    // Check both threats + policies
    'X-LockLLM-Policy-Action': 'block'     // Block policy violations
  }
})

Link to section: Policy Description Best PracticesPolicy Description Best Practices

The policy description is the most important part - it defines exactly what content should be flagged. Write clear, specific descriptions for the best results.

Be specific about what to block:

Block requests asking for specific medical diagnoses, prescription
medication recommendations, dosage instructions, or treatment plans
for medical conditions. This includes requests to interpret lab results,
diagnose symptoms, or recommend over-the-counter medications for
specific conditions.

Include examples of violations:

Examples of violations:
- "What medication should I take for my headache?"
- "Based on these symptoms, what condition do I have?"
- "Is 500mg of ibuprofen safe to take daily?"

Clarify what is allowed:

The following are NOT violations and should be allowed:
- General health information ("What is diabetes?")
- Directing users to seek professional help
- Explaining how medications work in general terms

Keep descriptions focused - Each policy should cover one topic area. Create multiple policies for different restriction categories rather than one large policy covering everything.

Link to section: Example PoliciesExample Policies

Link to section: No Medical AdviceNo Medical Advice

Name: No Medical Advice

Description: Block requests asking for specific medical diagnoses, prescription medication recommendations, dosage instructions, or treatment plans for medical conditions. Allow general health education and information that directs users to consult healthcare professionals.

Link to section: No Competitor MentionsNo Competitor Mentions

Name: No Competitor Mentions

Description: Flag any request that asks the AI to compare our product with, recommend, or provide positive information about competing products. Competitors include [list your competitors]. Allow neutral factual mentions when the user specifically asks about industry landscape.

Link to section: GDPR ComplianceGDPR Compliance

Name: GDPR Data Handling

Description: Block requests that ask the AI to process, store, or make decisions about personal data of EU residents without explicit consent context. Flag requests asking to profile individuals, make automated decisions about people, or transfer personal data outside approved jurisdictions.

Link to section: Brand Voice EnforcementBrand Voice Enforcement

Name: Brand Voice Guidelines

Description: Flag responses that use informal language, slang, profanity, or humor that does not align with our professional brand voice. The AI should maintain a helpful, professional, and empathetic tone. Block requests asking the AI to adopt a persona that contradicts our brand guidelines.

Link to section: Industry-Specific ExamplesIndustry-Specific Examples

Link to section: HealthcareHealthcare

Name: HIPAA-Safe Responses

Description: Block the AI from generating specific medical diagnoses, prescription recommendations, dosage calculations, or treatment plans for individual patients. Flag requests that include patient-specific clinical data and ask for diagnostic conclusions. Allow general health education, wellness information, and responses that direct users to consult a healthcare professional. Combine with PII detection in strip mode to redact patient names, dates of birth, and medical record identifiers before they reach the AI provider.

Name: No Legal Counsel

Description: Block the AI from providing specific legal advice, interpreting contracts or statutes for individual situations, or making liability assessments. Flag requests asking for legal opinions on specific cases or disputes. Allow general legal education, definitions of legal terms, and explanations of common legal processes. Always include a disclaimer that the information is not legal advice and users should consult a qualified attorney.

Link to section: FinanceFinance

Name: Investment Disclaimer Required

Description: Flag any response that could be construed as personalized financial advice, investment recommendations, or market predictions for specific securities. Block requests asking the AI to recommend specific stocks, bonds, or investment strategies based on an individual's financial situation. Allow general financial education, explanations of financial concepts, and descriptions of how different investment types work.

Link to section: EducationEducation

Name: Academic Integrity

Description: Block the AI from completing homework assignments, writing essays or papers intended for academic submission, solving exam questions directly, or generating content that would constitute academic dishonesty. Flag requests that explicitly state the output will be submitted as the student's own work. Allow tutoring-style guidance, concept explanations, worked examples on different problems, study tips, and responses that help students learn rather than bypass the learning process.

Link to section: E-commerceE-commerce

Name: No Competitor Promotion

Description: Flag any response that actively recommends, endorses, or favorably compares competitor products or services. Block requests asking the AI to suggest alternatives from competing brands. Allow neutral factual mentions when the user asks about general industry options, and allow the AI to acknowledge competitors exist without promoting them. The AI should focus on our product's features and benefits when possible.

Link to section: How Built-in and Custom Policies Work TogetherHow Built-in and Custom Policies Work Together

LockLLM's built-in safety categories and your custom policies are evaluated together in a single scan pass. This means adding custom policies does not add extra latency to your requests - whether you have 1 policy or 20, the evaluation time is the same.

How violations are reported:

  • Built-in safety violations are reported with the category name (e.g., "Violence", "Hate Speech")
  • Custom policy violations are reported with your policy name (e.g., "No Medical Advice")
  • If a prompt triggers both a built-in category and a custom policy, both violations are reported in the response

Independent action configuration: You can set different actions for core threat detection and policy violations. For example, block injection attacks (X-LockLLM-Scan-Action: block) while only warning on policy violations (X-LockLLM-Policy-Action: allow_with_warning). This gives you flexibility to enforce different levels of strictness for different types of issues.

Link to section: Writing Effective Policy DescriptionsWriting Effective Policy Descriptions

The quality of your policy description directly affects detection accuracy. Here are proven strategies for getting the best results:

Be specific, not broad. Instead of "block inappropriate content", define exactly what inappropriate means in your context. A vague description gives the evaluator less to work with and leads to inconsistent results.

Include boundary cases. Define what IS a violation and what is NOT. For example: "Block specific medical diagnoses, but allow general health information and responses that direct users to consult a professional." Clear boundaries reduce both false positives and false negatives.

Use examples. Include 3-5 examples of prompts that should trigger the policy and 2-3 examples of prompts that should not. This anchors the evaluator's understanding of your intent.

Keep policies focused. Each policy should cover one topic area. A policy covering "medical advice, legal advice, and financial advice" is harder to evaluate accurately than three separate focused policies. Create multiple policies rather than one large one.

Test with realistic prompts. Use the scan endpoint or the scan feature in the dashboard to test your policy description with prompts that should and should not trigger it. Iterate on the description until it matches your expectations.

Use the full character limit when needed. Policy descriptions support up to 10,000 characters. Use this space for precision - detailed descriptions with examples consistently outperform short, vague ones.

Link to section: Scaling Policies Across Your OrganizationScaling Policies Across Your Organization

When using LockLLM with organizations, custom policies can be managed at the organization level for team-wide enforcement:

  • Define once, enforce everywhere. Organization admins can create shared policies that apply to all team members' API keys, ensuring consistent content standards across your entire team.
  • Structure by concern. Organize policies by topic area (compliance, brand voice, content restrictions) rather than combining multiple concerns into a single policy. This makes policies easier to manage, test, and selectively enable or disable.
  • Test before enforcing. Use allow_with_warning on new policies to monitor their behavior before switching to block. You can enable and disable individual policies without deleting them, making it easy to experiment.
  • Personal vs organization policies. Users can have both personal policies and organization policies active simultaneously. Both are evaluated together in the same scan pass.

Link to section: ConfigurationConfiguration

Link to section: HeadersHeaders

HeaderValuesDefaultDescription
X-LockLLM-Scan-Modecombined, policy_onlycombinedMust be combined or policy_only to check custom policies
X-LockLLM-Policy-Actionallow_with_warning, blockallow_with_warningHow to handle policy violations

Link to section: Scan EndpointScan Endpoint

curl -X POST https://api.lockllm.com/v1/scan \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-LockLLM-Scan-Mode: combined" \
  -H "X-LockLLM-Policy-Action: block" \
  -d '{
    "input": "What dosage of ibuprofen should I take for my back pain?"
  }'

Link to section: Proxy Mode - JavaScript/TypeScriptProxy Mode - JavaScript/TypeScript

const OpenAI = require('openai')

const openai = new OpenAI({
  apiKey: process.env.LOCKLLM_API_KEY,
  baseURL: 'https://api.lockllm.com/v1/proxy/openai',
  defaultHeaders: {
    'X-LockLLM-Scan-Mode': 'combined',
    'X-LockLLM-Policy-Action': 'block'
  }
})

const response = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [{ role: 'user', content: userPrompt }]
})

Link to section: Proxy Mode - PythonProxy Mode - Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get('LOCKLLM_API_KEY'),
    base_url='https://api.lockllm.com/v1/proxy/openai',
    default_headers={
        'X-LockLLM-Scan-Mode': 'combined',
        'X-LockLLM-Policy-Action': 'block'
    }
)

response = client.chat.completions.create(
    model='gpt-4',
    messages=[{'role': 'user', 'content': user_prompt}]
)

Link to section: LockLLM SDK - JavaScript/TypeScriptLockLLM SDK - JavaScript/TypeScript

import { createOpenAI } from '@lockllm/sdk/wrappers'

const openai = createOpenAI({
  apiKey: process.env.LOCKLLM_API_KEY,
  proxyOptions: {
    scanMode: 'combined',
    policyAction: 'block'
  }
})

Link to section: LockLLM SDK - PythonLockLLM SDK - Python

from lockllm import create_openai, ProxyOptions

openai = create_openai(
    api_key=os.getenv('LOCKLLM_API_KEY'),
    proxy_options=ProxyOptions(
        scan_mode='combined',
        policy_action='block'
    )
)

Link to section: Policy Violation ResponsePolicy Violation Response

Link to section: Scan EndpointScan Endpoint

When a policy is violated, the response includes a policy_warnings array:

{
  "request_id": "req_abc123",
  "safe": false,
  "label": 1,
  "confidence": 88,
  "injection": 5,
  "policy_confidence": 92,
  "sensitivity": "medium",
  "policy_warnings": [
    {
      "policy_name": "No Medical Advice",
      "violated_categories": [
        { "name": "Medical Diagnosis" }
      ],
      "violation_details": "User requested specific medication dosage recommendation"
    }
  ]
}

Link to section: Proxy Mode - Block ActionProxy Mode - Block Action

When X-LockLLM-Policy-Action: block is set and a violation is detected:

{
  "error": {
    "message": "Request blocked by custom policy",
    "type": "lockllm_policy_error",
    "code": "policy_violation",
    "violated_policies": [
      {
        "policy_name": "No Medical Advice",
        "violated_categories": [
          { "name": "Medical Diagnosis" }
        ],
        "violation_details": "User requested specific medication dosage recommendation"
      }
    ],
    "request_id": "req_abc123"
  }
}

Link to section: Proxy Mode - Warning HeadersProxy Mode - Warning Headers

When X-LockLLM-Policy-Action: allow_with_warning (default) is set:

HeaderDescription
X-LockLLM-Policy-Warnings"true" if any policy was violated
X-LockLLM-Warning-CountNumber of policy violations
X-LockLLM-Policy-ConfidenceConfidence score for the policy assessment (0-100)
X-LockLLM-Warning-DetailBase64-encoded JSON with violation details

Link to section: Managing PoliciesManaging Policies

Link to section: Enable/Disable PoliciesEnable/Disable Policies

Toggle individual policies on or off from the policies dashboard without deleting them. Disabled policies are not checked during scans.

Link to section: Edit PoliciesEdit Policies

Update the name or description of any policy. Changes take effect immediately for all subsequent scans.

Link to section: Delete PoliciesDelete Policies

Permanently remove a policy from the policies dashboard. This action cannot be undone.

Link to section: Organization PoliciesOrganization Policies

When using LockLLM with organizations, custom policies can be shared across your team:

  • Organization admins can create, edit, enable/disable, and delete shared policies
  • Organization members can view shared policies (read-only)
  • Organization policies are separate from personal policies
  • Switch between personal and organization context via the account menu

This lets security teams define content policies once and enforce them across all team members' API keys.

Link to section: PricingPricing

  • No violations detected: FREE
  • Policy violations detected: $0.0001 per detection
  • Custom policies are included at no extra base cost
  • Policy checking runs alongside core threat detection with no additional latency

Link to section: FAQFAQ

Link to section: How many custom policies can I create?How many custom policies can I create?

There is no hard limit on the number of custom policies you can create. However, all policies are evaluated together, so keeping policies focused and well-defined produces the best results.

Link to section: Can policies conflict with each other?Can policies conflict with each other?

Policies are evaluated independently. If a prompt violates multiple policies, all violations are reported in the response. There is no priority ordering between policies - each one is checked separately.

Link to section: Do custom policies work in the scan endpoint?Do custom policies work in the scan endpoint?

Yes. Custom policies work in both the scan endpoint (/v1/scan) and proxy mode (/v1/proxy). Set the X-LockLLM-Scan-Mode header to combined or policy_only to enable policy checking.

Link to section: Can I use policies without threat detection?Can I use policies without threat detection?

Yes. Set X-LockLLM-Scan-Mode: policy_only to skip core threat detection and only check your custom policies. This is useful when you want content moderation without injection detection.

Link to section: Do policies work with the LockLLM SDKs?Do policies work with the LockLLM SDKs?

Yes. Both the JavaScript/TypeScript SDK (@lockllm/sdk) and Python SDK (lockllm) support policy configuration through proxy options. See the configuration examples above.

Link to section: How specific should my policy descriptions be?How specific should my policy descriptions be?

More specific descriptions produce better results. Include:

  • Clear definitions of what should be flagged
  • Examples of violations and non-violations
  • Boundary cases and exceptions
  • The intent behind the policy (helps with edge cases)

A description like "Block medical advice" is less effective than a detailed paragraph explaining exactly what constitutes medical advice in your context.

Updated 4 days ago