panda_guard.pipelines package
Submodules
panda_guard.pipelines.inference module
- class panda_guard.pipelines.inference.InferPipeline(config: InferPipelineConfig, verbose: bool = False)[source]
Bases:
objectInference pipeline for managing and executing attacks and defenses.
- Parameters:
config – Configuration for the inference pipeline, including attacker, defender, and judges.
verbose – Whether to enable verbose logging for debugging and transparency.
- calc_tokens() Dict[str, Dict[str, int]][source]
Calculate the token usage for both the attacker and defender, summarizing prompt and completion tokens.
- Returns:
Dictionary containing detailed token usage for both roles.
- log(messages: List[Dict[str, str]], stage: str | None = None)[source]
Log messages for each stage of the pipeline if verbose logging is enabled.
- Parameters:
messages – The messages to be logged at the current stage.
stage – A label for the current stage of the pipeline.
- parallel_judging(defense: List[Dict[str, str]], request: str) Dict[str, Any][source]
Perform parallel evaluation of the defense using multiple judges.
- Parameters:
defense – Messages that have been defended and need evaluation.
request – The original request for context in evaluation.
- Returns:
A dictionary containing the results from each judge.
- class panda_guard.pipelines.inference.InferPipelineConfig(attacker_config: ~panda_guard.role.attacks.base.BaseAttackerConfig | None = None, defender_config: ~panda_guard.role.defenses.base.BaseDefenderConfig | None = None, judge_configs: ~typing.List[~panda_guard.role.judges.base.BaseJudgeConfig] = <factory>)[source]
Bases:
objectConfiguration class for the inference pipeline.
- Parameters:
attacker_config – Configuration for the attacker, detailing its parameters and behavior.
defender_config – Configuration for the defender, detailing its parameters and behavior.
judge_configs – List of configurations for any judges used in evaluating the effectiveness of the defense.
- attacker_config: BaseAttackerConfig = None
- defender_config: BaseDefenderConfig = None
- judge_configs: List[BaseJudgeConfig]
- panda_guard.pipelines.inference.llm_register(attr: BaseAttacker | BaseDefender | BaseJudge) List[BaseLLM][source]
Register any LLM instances associated with the given attribute (attacker, defender, or judge).
- Parameters:
attr – An instance of an attacker, defender, or judge.
- Returns:
List of registered LLM instances.