Skip to content

Commit aceafa4

Browse files
committed
Address comments
1 parent a192074 commit aceafa4

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/checks/llm-base.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ export type LLMErrorOutput = z.infer<typeof LLMErrorOutput>;
6868
*
6969
* This helper provides a consistent way to handle errors across all LLM-based checks,
7070
* ensuring uniform error reporting and preventing tripwire triggers on execution failures.
71+
* Sets executionFailed=true to enable raiseGuardrailErrors handling.
7172
*
7273
* @param guardrailName - Name of the guardrail that encountered the error.
7374
* @param analysis - LLMErrorOutput containing error information.
74-
* @param checkedText - The original text that was being checked.
7575
* @param additionalInfo - Optional additional information to include in the result.
76-
* @returns GuardrailResult with tripwireTriggered=false and error information.
76+
* @returns GuardrailResult with tripwireTriggered=false, executionFailed=true, and error information.
7777
*/
7878
export function createErrorResult(
7979
guardrailName: string,
@@ -82,6 +82,8 @@ export function createErrorResult(
8282
): GuardrailResult {
8383
return {
8484
tripwireTriggered: false,
85+
executionFailed: true,
86+
originalException: new Error(String(analysis.info?.error_message || 'LLM execution failed')),
8587
info: {
8688
guardrail_name: guardrailName,
8789
flagged: analysis.flagged,
@@ -191,11 +193,7 @@ function buildFieldInstructionBlock(outputModel?: ZodTypeAny): string | null {
191193
export function buildFullPrompt(systemPrompt: string, outputModel?: ZodTypeAny): string {
192194
// Check if the system prompt already contains JSON output format instructions
193195
// Look for phrases that indicate output formatting requirements, not just mentions of JSON
194-
const hasJsonOutputInstructions =
195-
/respond\s+with\s+(a\s+)?json/i.test(systemPrompt) ||
196-
/output\s+(a\s+)?json/i.test(systemPrompt) ||
197-
/return\s+(a\s+)?json/i.test(systemPrompt) ||
198-
/format.*json/i.test(systemPrompt);
196+
const hasJsonOutputInstructions = /(?:respond|output|return)\s+(?:with\s+)?(?:a\s+)?json|format.*json/i.test(systemPrompt);
199197

200198
if (hasJsonOutputInstructions) {
201199
// If the system prompt already has detailed JSON instructions, use it as-is

src/evals/core/async-engine.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,9 @@ export class AsyncRunEngine implements RunEngine {
178178

179179
if (conversation.length === 0) {
180180
const guardrailContext = this.createConversationContext(context, []);
181-
const payload = this.isPromptInjectionGuardrail(guardrail)
182-
? sampleData
183-
: sampleData;
184181
return await guardrail.run(
185182
guardrailContext as GuardrailLLMContextWithHistory,
186-
payload
183+
sampleData
187184
);
188185
}
189186

0 commit comments

Comments
 (0)