import { TealEngine, TealGuard, PolicyMode } from 'tealtiger';
import { PromptInjectionGuardrail, PIIDetectionGuardrail } from 'tealtiger';
const engine = new TealEngine(
{
content: {
pii: { enabled: true, blockedTypes: ['ssn', 'credit_card'] },
},
},
{ mode: { default: PolicyMode.ENFORCE } }
);
const guard = new TealGuard({ policyDriven: true, engine });
guard.registerGuardrail(new PromptInjectionGuardrail({ sensitivity: 'high' }));
guard.registerGuardrail(new PIIDetectionGuardrail());
export default {
async fetch(request: Request): Promise<Response> {
const body = await request.json();
const decision = await guard.check(body.prompt);
if (decision.action === 'DENY') {
return new Response(JSON.stringify({ error: decision.reason }), {
status: 403,
headers: { 'Content-Type': 'application/json' },
});
}
// Forward to origin
return fetch('https://api.your-app.com/chat', {
method: 'POST',
body: JSON.stringify(body),
});
},
};