Skip to content

guardrails

Modules:

Name Description
scanner
transformed_embedding_scanner

Classes:

Name Description
EmbeddingScanner

Defines an interface for scanning input embeddings for unauthorized prompts.

TransformedEmbeddingScanner

Scans LLM input embeddings for unauthorized prompts.

EmbeddingScanner

Bases: Protocol

Defines an interface for scanning input embeddings for unauthorized prompts.

Methods:

Name Description
scan

Scan and detect unauthorized embeddings in the input.

scan abstractmethod

scan(input_embeddings: Tensor) -> None

Scan and detect unauthorized embeddings in the input.

Parameters:

Name Type Description Default

input_embeddings

Tensor

The input embeddings to be scanned.

required

Raises:

Type Description
RuntimeError

If any of the input embeddings are invalid.

TransformedEmbeddingScanner

Bases: EmbeddingScanner

Scans LLM input embeddings for unauthorized prompts.

Methods:

Name Description
__init__

Construct a TransformedEmbeddingScanner.

scan

Scan and detect unauthorized embeddings in the input.

__init__

__init__(
    tokenizer: PreTrainedTokenizer
    | PreTrainedTokenizerFast,
    model: CausalModelT,
) -> None

Construct a TransformedEmbeddingScanner.

Parameters:

Name Type Description Default

tokenizer

PreTrainedTokenizer | PreTrainedTokenizerFast

Tokenizer for the LLM model.

required

model

CausalModelT

The LLM model whose input embeddings to check against.

required

scan

scan(input_embeddings: Tensor) -> None

Scan and detect unauthorized embeddings in the input.

Parameters:

Name Type Description Default

input_embeddings

Tensor

Input embeddings for LLM generation.

required

Raises:

Type Description
ValueError

If the dtype, embedding dimension, or batch size of the input embeddings are invalid.

RuntimeError

If any of the input embeddings are invalid.