UNPKG
@sisu-ai/mw-guardrails
Version:
latest (8.0.1)
8.0.1
8.0.0
7.0.0
6.0.1
6.0.0
5.0.0
4.0.3
4.0.2
4.0.1
4.0.0
3.0.3
3.0.2
3.0.1
3.0.0
2.0.0
1.0.1
1.0.0
Policy guardrails to short-circuit unsafe input.
github.com/finger-gun/sisu
finger-gun/sisu
@sisu-ai/mw-guardrails
/
dist
/
index.js
9 lines
(8 loc)
•
252 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
export
const
withGuardrails
= (
policy
) =>
async
(ctx, next) => {
const
violation =
await
policy
(ctx.
input
??
''
);
if
(violation) { ctx.
messages
.
push
({
role
:
'assistant'
,
content
: violation });
return
; }
await
next
(); };