@@ -176,26 +176,28 @@ export const moderationCheck: CheckFn<ModerationContext, string, ModerationConfi
176176 } catch ( fallbackError ) {
177177 // If fallback fails, return execution failure
178178 // This allows runGuardrails to handle based on raiseGuardrailErrors flag
179+ const errorObj = ensureError ( fallbackError ) ;
179180 return {
180181 tripwireTriggered : false ,
181182 executionFailed : true ,
182- originalException : ensureError ( fallbackError ) ,
183+ originalException : errorObj ,
183184 info : {
184185 checked_text : data ,
185- error : ensureError ( fallbackError ) . message ,
186+ error : errorObj . message ,
186187 } ,
187188 } ;
188189 }
189190 } else {
190191 // Non-404 error from context client - return execution failure
191192 // This allows runGuardrails to handle based on raiseGuardrailErrors flag
193+ const errorObj = ensureError ( error ) ;
192194 return {
193195 tripwireTriggered : false ,
194196 executionFailed : true ,
195- originalException : ensureError ( error ) ,
197+ originalException : errorObj ,
196198 info : {
197199 checked_text : data ,
198- error : ensureError ( error ) . message ,
200+ error : errorObj . message ,
199201 } ,
200202 } ;
201203 }
@@ -247,13 +249,14 @@ export const moderationCheck: CheckFn<ModerationContext, string, ModerationConfi
247249 } ;
248250 } catch ( error ) {
249251 console . warn ( 'AI-based moderation failed:' , error ) ;
252+ const errorObj = ensureError ( error ) ;
250253 return {
251254 tripwireTriggered : false ,
252255 executionFailed : true ,
253- originalException : ensureError ( error ) ,
256+ originalException : errorObj ,
254257 info : {
255258 checked_text : data ,
256- error : ensureError ( error ) . message ,
259+ error : errorObj . message ,
257260 } ,
258261 } ;
259262 }
0 commit comments