Files
portkey-ai--gateway/plugins/promptfoo/guard.ts
T
wehub-resource-sync 3cd11ababe
Check Markdown links / linkChecker (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:38:56 +08:00

44 lines
892 B
TypeScript

import {
HookEventType,
PluginContext,
PluginHandler,
PluginParameters,
} from '../types';
import { getText } from '../utils';
import { postPromptfoo } from './globals';
import { GuardResult, PromptfooResult } from './types';
export const handler: PluginHandler = async (
context: PluginContext,
parameters: PluginParameters,
eventType: HookEventType
) => {
let error = null;
let verdict = true;
let data = null;
try {
const guardObject = {
input: getText(context, eventType),
};
const result = await postPromptfoo<GuardResult>(
'guard',
guardObject,
parameters.timeout
);
// For now, we only check for jailbreak
if (result.results[0].categories.jailbreak) {
verdict = false;
}
data = result.results[0];
} catch (e: any) {
delete e.stack;
error = e;
}
return { error, verdict, data };
};