code_of_conduct#
enkrypt.code_of_conduct(rules=None, *, policy=None, on_violation="block", on_error="block")
Flags text that breaks your own rules, judged by Enkrypt’s policy violation detector.
Allowed actions |
|
Default action |
|
Enkrypt detector |
|
Inline rules or a saved policy#
Pass the rules in code, as one string or a list:
no_advice = enkrypt.code_of_conduct("Never give personalized investment advice.")
house_rules = enkrypt.code_of_conduct([
"Never give personalized investment advice.",
"Never mention competitors by name.",
])
Or name a Code of Conduct policy saved in Enkrypt, so the rules are managed in Enkrypt’s dashboard:
house_rules = enkrypt.code_of_conduct(policy="brokerage-policy")
Pass one or the other; passing both, or neither, raises ValueError. A policy name Enkrypt does not know is an Enkrypt error, so the guard’s on_error applies.
In Enkrypt, a “policy” is a Code of Conduct rule set like this one. It is not a saved guardrail, which is a set of detectors; for those, see guardrail.
Which rule broke#
Inline rules are sent as a numbered list, so Enkrypt reports which rule was broken and why. The explanation appears in the guard’s message:
Your message does not comply with our usage policies. Please revise and try again. (policy_violation: Directly requests personalized investment advice.)
One guard, both directions#
The same guard can check the prompt and the answer:
no_advice = enkrypt.code_of_conduct("Never give personalized investment advice.")
agent = Agent(
FunctionModel(model),
capabilities=[
InputGuardrail(guard=[no_advice]),
OutputGuardrail(guard=[no_advice]),
],
)
A prompt asking for advice is refused before the model runs. A harmless prompt whose answer gives advice ends with OutputBlocked, because block on an answer raises. Full script: Code of conduct.