Protect SDK rejects an input

Fix a protect() call that errors instead of returning a result

Calling protect() fails instead of returning a dictionary with a status key, and nothing gets screened. Two causes produce this: an unsupported input type, or an unrecognized check name in protect_rules. If neither cause matches your situation, for example a missing API key when constructing Protect(), it’s a different problem.

The input type isn’t one Protect screens

Protect screens text, image, and audio input, one at a time. Send it an image set, a PDF, or a knowledge base input, and the call fails before it screens anything.

Fix: send one supported input per call.

The rule names a check protect() doesn’t accept

Each rule in protect_rules names a check with a metric key, and an unaccepted value fails the call before anything is screened. See Run Protect from the SDK for the accepted metric values.

Fix: match the metric value to one of the accepted names.

# Fails before anything is screened
rules = [{"metric": "jailbreak"}]

# Fixed
rules = [{"metric": "prompt_injection"}]

Confirm the exact spelling before you ship it, since a typo fails the same way as an unsupported name.

Dive deeper

Was this page helpful?

Questions & Discussion