Coverage for .venv/lib/python3.13/site-packages/litellm/proxy/guardrails/guardrail_hooks/openai/base.py: 67%
7 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
1from typing import TYPE_CHECKING
3from litellm.litellm_core_utils.prompt_templates.common_utils import (
4 get_last_user_message,
5)
7if TYPE_CHECKING: 7 ↛ 8line 7 didn't jump to line 8 because the condition on line 7 was never true
8 from litellm.types.llms.openai import AllMessageValues
11class OpenAIGuardrailBase:
12 """
13 Base class for OpenAI guardrails.
14 """
16 def get_user_prompt(self, messages: list["AllMessageValues"]) -> str | None:
17 """
18 Get the last consecutive block of messages from the user.
20 Example:
21 messages = [
22 {"role": "user", "content": "Hello, how are you?"},
23 {"role": "assistant", "content": "I'm good, thank you!"},
24 {"role": "user", "content": "What is the weather in Tokyo?"},
25 ]
26 get_user_prompt(messages) -> "What is the weather in Tokyo?"
27 """
28 return get_last_user_message(messages)