For the complete documentation index, see llms.txt. This page is also available as Markdown.

Any LLM as a Guardrail

Open In Colab

Install dependencies

import nest_asyncio

nest_asyncio.apply()

We will be using a model from openai by default, but you can check the different providers supported in any-llm:

https://mozilla-ai.github.io/any-llm/providers/

import os
from getpass import getpass

if "OPENAI_API_KEY" not in os.environ:
    print("OPENAI_API_KEY not found in environment!")
    api_key = getpass("Please enter your OPENAI_API_KEY: ")
    os.environ["OPENAI_API_KEY"] = api_key
    print("OPENAI_API_KEY set for this session!")
else:
    print("OPENAI_API_KEY found in environment.")

Create the guardrail

Try it with different models / policies / inputs

Last updated