Skip to content

Support for custom guardrail rules #7

@nagasatish007

Description

@nagasatish007

Which SDK is this for?

Both

Feature Type

New Guardrail

Problem Statement

The built-in guardrails (PII detection, prompt injection, content moderation) are great, but I need to add custom rules specific to my domain (e.g., blocking certain industry-specific terms).

Proposed Solution

Add a plugin system that allows developers to register custom guardrail functions that run alongside the built-in ones.

Alternatives Considered

No response

Use Case

In my healthcare application, I need to block certain medical terms and ensure HIPAA compliance beyond standard PII detection. I want to define custom rules without forking the SDK.

Example Code

import { TealOpenAI, CustomGuardrail } from 'tealtiger';

const medicalTermsGuardrail: CustomGuardrail = {
  name: 'medical-terms-blocker',
  check: async (input: string) => {
    const blockedTerms = ['diagnosis', 'prescription', 'treatment'];
    const found = blockedTerms.find(term => input.toLowerCase().includes(term));
    
    return {
      passed: !found,
      reason: found ? `Blocked medical term: ${found}` : undefined,
    };
  },
};

const client = new TealOpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  enableGuardrails: true,
  customGuardrails: [medicalTermsGuardrail],
});

Would you like to contribute this feature?

  • I'm willing to submit a PR to implement this feature
  • I need help implementing this feature

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions