Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
boolean guardrail works now
  • Loading branch information
roh26it committed Jul 14, 2025
commit a07e2a1e865901e45951dbfc580ba8e618881dfc
2 changes: 2 additions & 0 deletions plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { handler as portkeymoderateContent } from './portkey/moderateContent';
import { handler as portkeylanguage } from './portkey/language';
import { handler as portkeypii } from './portkey/pii';
import { handler as portkeygibberish } from './portkey/gibberish';
import { handler as portkeyprompt } from './portkey/prompt';
import { handler as aporiavalidateProject } from './aporia/validateProject';
import { handler as sydelabssydeguard } from './sydelabs/sydeguard';
import { handler as pillarscanPrompt } from './pillar/scanPrompt';
Expand Down Expand Up @@ -75,6 +76,7 @@ export const plugins = {
language: portkeylanguage,
pii: portkeypii,
gibberish: portkeygibberish,
prompt: portkeyprompt,
},
aporia: {
validateProject: aporiavalidateProject,
Expand Down
20 changes: 14 additions & 6 deletions plugins/portkey/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ class VerdictChecker {

boolean() {
this.expectedResult = this.expectedResult as BooleanExpectedResult;
return (
this.completionText.toLowerCase() ===
this.expectedResult.booleanResult.toString().toLowerCase()
);
return this.completionText
.toLowerCase()
.includes(this.expectedResult.booleanResult.toString().toLowerCase());
}

choices() {
Expand All @@ -139,13 +138,18 @@ class VerdictChecker {

const getPromptCompletion = async (
promptId: string,
variables: Record<string, string>
variables: Record<string, string>,
credentials: Record<string, string>
) => {
const response = await fetch(
`${process.env.PORTKEY_API_URL}/prompts/${promptId}/completions`,
{
method: 'POST',
body: JSON.stringify({ variables }),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${credentials.apiKey}`,
},
}
);
return response.json();
Expand Down Expand Up @@ -173,15 +177,19 @@ export const handler: PluginHandler = async (
}

try {
console.log('Getting prompt completion');
const responseJson: any = await getPromptCompletion(
parameters.promptId,
variables
variables,
parameters.credentials || {}
);
console.log('Prompt completion received', responseJson.choices[0].message);
const result = new VerdictChecker(
responseJson.choices[0].message.content,
parameters.expectedResult,
parameters.verdictType
).check();
console.log('Verdict check result', result);
verdict = result.verdict;
data = result.data;
} catch (e) {
Expand Down