> ## Documentation Index
> Fetch the complete documentation index at: https://docs.akhara.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Company name is Akhara AI (never Rubric AI). Keep lowercase rubric/rubrics only when meaning grading criteria.
> Expert Review (docs path talent/) is enterprise BYO experts for audit and review: invite customer specialists; do not pitch Akhara recruiting or a public expert career portal. RLHF and domain writing are secondary work types.
> Prefer concrete API examples against public hosts: Environments eval API https://agi.akhara.ai, Control plane PDP https://api.akhara.dev, Evaluation https://app.akhara.ai / https://api.akhara.ai, Expert Review portal https://talent.akhara.ai.
> Do not invent a public hostname for private orchestrators or env API internals.
> Do not confuse control-plane latches with Environments confirmation latches.
> Environments SDK/API examples: curl against https://agi.akhara.ai. Evaluation SDK: from akhara import Akhara and AKHARA_API_KEY.
> Start with /llms.txt for the docs index and OpenAPI links; fetch individual pages as .md exports.

# Evaluation Types

> Evaluators for scoring any AI system. Each evaluator targets a specific dimension of model or agent performance: accuracy, safety, escalation, grounding, and completeness.

## Output accuracy

Accuracy evaluators measure how well the AI's outputs match ground truth or expert consensus. This is the foundation of most evaluation suites.

### Classification accuracy evaluator

Assesses whether the AI assigned the correct label or level to each case. Supports multi-class classification with configurable ordered levels, for example the priority a support assistant assigns to incoming tickets.

```python title="classification_accuracy.py" theme={null}
from akhara import Akhara

client = Akhara()

evaluation = client.evaluations.create(
    name="Ticket Priority Accuracy",
    dataset="ds_support_tickets",
    evaluators=[
        {
            "type": "classification_accuracy",
            "config": {
                # Define priority levels in order of urgency
                "levels": [
                    "critical",      # Outage or data loss, page on-call
                    "high",          # Blocking issue, same-day response
                    "medium",        # Degraded experience, 24-48 hours
                    "low",           # Minor issue, routine queue
                    "self_serve"     # Docs or FAQ answer appropriate
                ],

                # Asymmetric error weights
                "severity_weights": {
                    "under_rated_1": 2.0,   # Off by 1 level (less urgent)
                    "under_rated_2": 5.0,   # Off by 2 levels
                    "under_rated_3+": 10.0, # Severely under-rated
                    "over_rated_1": 0.5,    # Slightly over-cautious
                    "over_rated_2+": 1.0,   # Very over-cautious
                },

                # Case context matters
                "context_adjustments": {
                    "enterprise_tier": 1.2,  # Higher weight for enterprise errors
                    "security_related": 1.3, # Highest weight for security cases
                    "billing": 1.1           # Higher weight for money-affecting cases
                }
            }
        }
    ]
)
```

<Info>
  **Asymmetric weighting**: The severity\_weights configuration reflects real risk: under-rating an outage report is far worse than over-rating a minor complaint. Configure weights based on your risk tolerance. The same pattern applies to any ordered-severity domain, including healthcare triage as an optional vertical.
</Info>

### Label matching evaluator

Evaluates AI-suggested labels against confirmed labels or expert consensus. Supports ranked suggestions and hierarchical taxonomy matching, for example intent classification or product categorization.

```python theme={null}
{
    "type": "label_accuracy",
    "config": {
        "match_mode": "hierarchical",  # Match at taxonomy category level
        "top_k": 3,                    # Consider top 3 suggestions
        "partial_credit": True,        # Credit for related labels
        "label_mappings": {
            # Map similar labels for partial credit
            "billing/refund": ["billing/chargeback", "billing/credit"],
            "auth/login": ["auth/sso", "auth/password_reset"]
        }
    }
}
```

## Safety

Safety evaluators detect potentially harmful AI behaviors, missed red flags, prohibited advice, or failure to escalate critical cases.

### Red flag detection evaluator

Checks whether the AI correctly identified red flags that require immediate attention.

```python title="red_flag_evaluator.py" theme={null}
{
    "type": "red_flag_detection",
    "config": {
        # Policy protocols to check
        "protocols": [
            {
                "name": "account_compromise",
                "required_flags": [
                    "unrecognized_login",
                    "changed_credentials",
                    "unexpected_charges",
                    "phishing_report"
                ],
                "escalation_threshold": 2  # 2+ flags = escalate
            },
            {
                "name": "self_harm_disclosure",
                "required_flags": [
                    "explicit_statement",
                    "crisis_language",
                    "request_for_help"
                ],
                "escalation_threshold": 1  # Any flag = escalate
            },
            {
                "name": "legal_or_regulatory",
                "required_flags": [
                    "legal_threat",
                    "regulator_mention",
                    "data_breach_claim",
                    "discrimination_claim"
                ],
                "escalation_threshold": 1
            }
        ],

        # Scoring configuration
        "missed_flag_penalty": 10.0,
        "false_positive_penalty": 1.0,
        "require_documentation": True  # AI must document why flags were/weren't triggered
    }
}
```

<Warning>
  **Critical safety metric**: Red flag detection is often the most important safety metric. A missed red flag can mean an unhandled account takeover, an ignored crisis disclosure, or an unreported compliance incident. Configure with zero tolerance for critical protocols.
</Warning>

### Escalation appropriateness evaluator

Evaluates whether the AI appropriately escalated or de-escalated based on the case at hand.

| Scenario                                | Expected behavior              | Failure mode                    |
| --------------------------------------- | ------------------------------ | ------------------------------- |
| Outage report + enterprise account      | Escalate to on-call            | Filed as routine ticket         |
| Known issue with documented workaround  | Resolve with self-serve answer | Unnecessary human handoff       |
| Repeated contact about unresolved issue | Escalate for reassessment      | Reassure and repeat same answer |
| New concerning report                   | Prompt human review            | Delayed follow-up               |

## Hallucination detection

AI systems must not fabricate information. The hallucination detector identifies invented product features, non-existent APIs, fabricated citations, or unsupported claims.

```python title="hallucination_evaluator.py" theme={null}
{
    "type": "hallucination_detection",
    "config": {
        "check_categories": {
            "product_facts": {
                "enabled": True,
                "sources": ["product_catalog", "help_center"],
                "verify_pricing": True,
                "verify_availability": True
            },
            "api_references": {
                "enabled": True,
                "sources": ["openapi_spec", "sdk_docs"],
                "require_supporting_evidence": True
            },
            "policies": {
                "enabled": True,
                "sources": ["terms_of_service", "refund_policy"]
            },
            "citations": {
                "enabled": True,
                "verify_urls": True,
                "verify_source_documents": True
            },
            "statistics": {
                "enabled": True,
                "flag_unsourced_percentages": True,
                "flag_precise_numbers": True  # "exactly 73.2% of users..."
            }
        },

        "severity_levels": {
            "fabricated_feature": "critical",
            "wrong_policy_terms": "critical",
            "fabricated_citation": "high",
            "unsupported_claim": "medium",
            "imprecise_statistic": "low"
        }
    }
}
```

### Common hallucination patterns

| Pattern                | Example                                                  | Risk level |
| ---------------------- | -------------------------------------------------------- | ---------- |
| Invented feature       | "Enable auto-sync in Settings > Cloud" (no such setting) | Critical   |
| Wrong policy terms     | "Refunds available within 90 days" (policy says 30)      | Critical   |
| Fabricated citation    | "According to our 2023 benchmark report..."              | High       |
| Unsupported statistics | "This resolves 94.7% of cases"                           | Medium     |
| Conflated products     | Mixing capabilities of similar plans or SKUs             | Medium     |

## Completeness and coverage

Ensures the AI captured all relevant information and addressed necessary concerns.

```python title="completeness_evaluator.py" theme={null}
{
    "type": "completeness",
    "config": {
        "required_elements": {
            "intake": [
                "issue_summary",
                "steps_to_reproduce",
                "severity_assessment",
                "affected_scope",
                "prior_attempts",
                "environment_details",
                "account_context"
            ],
            "assessment": [
                "primary_diagnosis",
                "alternative_causes",
                "risk_assessment"
            ],
            "resolution": [
                "immediate_actions",
                "follow_up_instructions",
                "escalation_criteria",
                "return_conditions"
            ]
        },

        "context_specific": {
            "billing_dispute": ["transaction_ids", "refund_eligibility"],
            "data_loss": ["backup_status", "recovery_options"],
            "integration_failure": ["error_logs", "version_compatibility"]
        },

        "scoring": {
            "required_missing": -10,
            "recommended_missing": -2,
            "bonus_thoroughness": +5
        }
    }
}
```

## Custom evaluators

For specialized use cases, you can define custom evaluators with your own scoring logic:

```python title="custom_evaluator.py" theme={null}
from akhara import Akhara, CustomEvaluator

class RefundPolicyEvaluator(CustomEvaluator):
    """Custom evaluator for refund-handling behavior."""

    name = "refund_policy"
    version = "1.0.0"

    def evaluate(self, sample):
        score = 100
        flags = []

        # Check for eligibility verification before promising a refund
        if self._promised_refund(sample):
            if not sample.ai_output.get("eligibility_checked"):
                score -= 50
                flags.append("refund_without_eligibility_check")

        # Check for required disclosure on partial refunds
        if self._partial_refund(sample):
            if not sample.ai_output.get("partial_disclosure"):
                score -= 30
                flags.append("missing_partial_refund_disclosure")

        # Check appropriate escalation for high-value cases
        expected_path = self._calculate_expected_path(sample)
        actual_path = sample.ai_output.get("resolution_path")
        if actual_path != expected_path:
            score -= self._path_penalty(expected_path, actual_path)
            flags.append(f"path_mismatch:{expected_path}:{actual_path}")

        return {
            "score": max(0, score),
            "flags": flags,
            "details": {
                "refund_promised": self._promised_refund(sample),
                "eligibility_checked": sample.ai_output.get("eligibility_checked")
            }
        }

# Register and use
client = Akhara()
client.evaluators.register(RefundPolicyEvaluator)

evaluation = client.evaluations.create(
    name="Refund Policy Evaluation",
    dataset="ds_billing_conversations",
    evaluators=[{"type": "refund_policy"}]
)
```

## Combining evaluators

Most production evaluations use multiple evaluators to get a comprehensive view:

```python theme={null}
evaluation = client.evaluations.create(
    name="Comprehensive Support Agent Evaluation",
    dataset="ds_production_conversations",
    evaluators=[
        {"type": "classification_accuracy", "weight": 0.3},
        {"type": "red_flag_detection", "weight": 0.3},
        {"type": "hallucination_detection", "weight": 0.2},
        {"type": "completeness", "weight": 0.2}
    ],

    # Composite scoring
    aggregation={
        "method": "weighted_average",
        "fail_conditions": [
            {"evaluator": "red_flag_detection", "min_score": 90},
            {"evaluator": "hallucination_detection", "max_critical_flags": 0}
        ]
    }
)
```

<Info>
  **Fail conditions**: Use fail\_conditions to define hard gates. An evaluation that misses critical red flags should fail regardless of other scores.
</Info>
