Skip to content

Commit 1282c2d

Browse files
committed
Refactor safety response handling in guardrails.mdx for js
1 parent cc2c33f commit 1282c2d

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

src/oss/langchain/guardrails.mdx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,7 @@ def safety_guardrail(state: AgentState, runtime: Runtime) -> dict[str, Any] | No
531531
result = safety_model.invoke([{"role": "user", "content": safety_prompt}])
532532

533533
if "UNSAFE" in result.content:
534-
return {
535-
"messages": [{
536-
"role": "assistant",
537-
"content": "I cannot provide that response. Please rephrase your request."
538-
}],
539-
"jump_to": "end"
540-
}
534+
last_message.content = "I cannot provide that response. Please rephrase your request."
541535

542536
return None
543537

@@ -590,14 +584,7 @@ const safetyGuardrailMiddleware = () => {
590584
]);
591585

592586
if (result.content.toString().includes("UNSAFE")) {
593-
return {
594-
messages: [
595-
new AIMessage(
596-
"I cannot provide that response. Please rephrase your request."
597-
)
598-
],
599-
jumpTo: "end",
600-
};
587+
lastMessage.content = "I cannot provide that response. Please rephrase your request.";
601588
}
602589

603590
return;

0 commit comments

Comments
 (0)