Skip to main content
Intrinsic functions for Guardian safety and hallucination detection. The guardian-core LoRA adapter uses a <guardian> protocol tag in the last user message to specify system prompt, criteria, and scoring schema. This differs from other intrinsics, which rely on the instruction field in io.yaml.

Functions

FUNC policy_guardrails

policy_guardrails(context: ChatContext, backend: AdapterMixin, policy_text: str) -> str
Checks whether text complied with specified policy. Uses the policy_guardrails LoRA adapter to judge whether the scenario described in the last message in context is compliant with the given policy_text. :param context: Chat context containing the conversation to evaluate. :param backend: Backend instance that supports LoRA adapters. :param policy_text: Policy against with compliance is to be checked :return: Compliance as a “Yes/No/Ambiguous” label (Yes = compliant).

FUNC guardian_check

guardian_check(context: ChatContext, backend: AdapterMixin, criteria: str, target_role: str = 'assistant') -> float
Check whether text meets specified safety/quality criteria. Uses the guardian-core LoRA adapter to judge whether the last message from target_role in context meets the given criteria. Args:
  • context: Chat context containing the conversation to evaluate.
  • backend: Backend instance that supports LoRA adapters.
  • criteria: Description of the criteria to check against. Can be a key from :data:CRITERIA_BANK (e.g. "harm") or a custom criteria string.
  • target_role: Role whose last message is being evaluated ("user" or "assistant").
Returns:
  • Risk score as a float between 0.0 (no risk) and 1.0 (risk detected).

FUNC factuality_detection

factuality_detection(context: ChatContext, backend: AdapterMixin) -> float
Determine is the last response is factually incorrect. Intrinsic function that evaluates the factuality of the assistant’s response to a user’s question. The context should end with a user question followed by an assistant answer. :param context: Chat context containing user question and assistant answer. :param backend: Backend instance that supports LoRA/aLoRA adapters. :return: Factuality score as a “yes/no” label (yes = factually incorrect).

FUNC factuality_correction

factuality_correction(context: ChatContext, backend: AdapterMixin) -> float
Corrects the last response so that it is factually correct. Intrinsic function that corrects the assistant’s response to a user’s question relative to the given contextual information. :param context: Chat context containing user question and assistant answer. :param backend: Backend instance that supports LoRA/aLoRA adapters. :return: Correct assistant response.