Policies

A policy is a quality gate for an AI app: a group of rules checked against the metrics its evaluations produce. Each rule reports PASS or FAIL with a short explanation, so the app either meets the bar you defined or tells you which rule it misses.

# policies.yaml
policies:
  - key: "rag_quality_gate_v1"
    display_name: "RAG Quality Gate v1"
    description: "Baseline quality thresholds for production RAG systems."
    rules:
      - key: "hallucinations_are_uncommon"
        display_name: "Hallucinations are Uncommon"
        definition:
          type: "threshold"
          metric: "hallucination"
          operator: "<"
          threshold: 0.05
        scope: "all_latest"

Rules

A rule’s definition states what is checked:

  • exists passes if the named metric was computed at all, which catches evaluations that silently stopped reporting a number.
  • threshold passes if the metric exists and all of its values in scope satisfy operator against threshold.

Its scope states which metric values count. all_latest takes the metrics of the latest run of every evaluation key in the app; a fine-grained scope narrows this by evaluation_keys, task_specification_keys, scorer_keys and metric_keys, which keeps experimental evaluations from affecting the verdict. Either way only the latest evaluation per key is considered.

Working with policies

Policies are attached to the app, not to a single evaluation: apply a policy file with lf set policies, or declare the policies in the policies section of a run config so they are applied together with the evaluation. After the evaluations finish, lf overview policies prints each rule’s result, and lf export policies writes the current policies back to YAML. See the policies guide for a quickstart.

A policy that groups multiple rules together.

Configuration

Properties


key string required

A key for the policy within the AI app.

Pattern: ^[a-zA-Z0-9_\-]+$
Max Length: 250


display_name string required

The display name of the policy.


description string

The description of the policy.

Default: None


rules array[PolicyRule] required

The list of rules that belong to this policy.

RAG Quality Gate v1
# ...
policies:
  - key: "rag_quality_gate_v1"
    display_name: "RAG Quality Gate v1"
    description: "Baseline quality thresholds for production RAG systems."
    rules:
      - key: "faithfulness_is_high"
        display_name: "Faithfulness is High"
        description: "Faithfulness must exceed 70%."
        definition:
          type: "threshold"
          metric: "faithfulness"
          operator: ">"
          threshold: 0.7
        scope: "all_latest"
      - key: "faithfulness_is_measured"
        display_name: "Faithfulness is Measured"
        description: "Faithfulness metric must be computed."
        definition:
          type: "exists"
          metric: "faithfulness"
        scope: "all_latest"
      - key: "faithfulness_in_rag_eval"
        display_name: "Faithfulness in RAG Evaluation"
        description: "Faithfulness must be measured in the specific RAG evaluation."
        definition:
          type: "exists"
          metric: "faithfulness"
        scope:
          evaluation_keys:
            - "rag-faithfulness"
          task_specification_keys:
            - "rag-faithfulness"