@@ -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 */
7878export 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 {
191193export 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- / r e s p o n d \s + w i t h \s + ( a \s + ) ? j s o n / i. test ( systemPrompt ) ||
196- / o u t p u t \s + ( a \s + ) ? j s o n / i. test ( systemPrompt ) ||
197- / r e t u r n \s + ( a \s + ) ? j s o n / i. test ( systemPrompt ) ||
198- / f o r m a t .* j s o n / i. test ( systemPrompt ) ;
196+ const hasJsonOutputInstructions = / (?: r e s p o n d | o u t p u t | r e t u r n ) \s + (?: w i t h \s + ) ? (?: a \s + ) ? j s o n | f o r m a t .* j s o n / i. test ( systemPrompt ) ;
199197
200198 if ( hasJsonOutputInstructions ) {
201199 // If the system prompt already has detailed JSON instructions, use it as-is
0 commit comments