Skip to content

Base

Base safety configuration.

This module contains the base abstract class for all safety configuration builders.

BaseSafetyConfigBuilder

Bases: ABC

Base abstract class for all safety configuration builders.

Tip

To minimize runtime latency, ensure that all computationally expensive operations (e.g., string formatting, data processing, configuration loading) are performed during the __init__ phase. The get_string and to_dict methods should ideally return pre-computed values.

get_string() abstractmethod

Returns the formatted prompt string for LLM context.

Returns:

Name Type Description
str str

The formatted prompt string.

to_dict() abstractmethod

Returns a structured dictionary representation of the configuration.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The structured dictionary.

with_defaults(**kwargs) abstractmethod classmethod

Factory method to create a config instance with default values and optional overrides.

Parameters:

Name Type Description Default
**kwargs Any

Optional overrides for the configuration attributes.

{}

Returns:

Name Type Description
T T

An instance of the configuration.