> ## 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.

# Evaluating LLM Applications

> Guide for teams building LLM-powered healthcare features, chatbots, Q&A systems, summarization, and more.

## Overview

If you're using LLMs (GPT-4, Claude, Llama, etc.) for healthcare applications, this guide covers how to set up effective evaluation for clinical safety and quality.

<CardGroup cols={2}>
  <Card title="Patient-Facing Chatbots" icon="comments">
    Symptom checkers, health Q\&A, appointment scheduling
  </Card>

  <Card title="Clinical Q&A" icon="circle-question">
    Provider-facing knowledge assistants, drug information
  </Card>

  <Card title="Summarization" icon="file-lines">
    Visit summaries, discharge instructions, chart review
  </Card>

  <Card title="Documentation" icon="pen">
    Note generation, letter writing, form filling
  </Card>
</CardGroup>

## What to Evaluate

LLM healthcare applications need evaluation across multiple dimensions:

| Dimension               | What It Measures                    | Why It Matters             |
| ----------------------- | ----------------------------------- | -------------------------- |
| **Clinical Accuracy**   | Factual correctness of medical info | Wrong info = patient harm  |
| **Safety**              | Appropriate caution and escalation  | Must not miss emergencies  |
| **Hallucination**       | Made-up facts or citations          | LLMs confidently fabricate |
| **Guideline Adherence** | Following clinical protocols        | Ensures standard of care   |
| **Completeness**        | Covering all relevant points        | Missing info = missed care |
| **Tone & Empathy**      | Appropriate communication style     | Patient experience matters |

## Sample Data Format

Structure your evaluation data to capture both inputs and outputs:

```python theme={null}
# Log a chatbot interaction for evaluation
client.log(
    project="patient-chatbot",
    
    input={
        # The conversation history
        "messages": [
            {"role": "user", "content": "I've had a headache for 3 days"},
            {"role": "assistant", "content": "I'm sorry to hear that..."},
            {"role": "user", "content": "It's getting worse and light bothers my eyes"},
        ],
        
        # Context provided to the LLM
        "system_prompt": "You are a medical triage assistant...",
        "patient_context": {
            "age": 34,
            "medications": ["birth_control"]
        }
    },
    
    output={
        # The LLM's response
        "response": "Those symptoms - a worsening headache with light sensitivity - could indicate something that needs prompt medical attention...",
        
        # Extracted structured data (if your app does this)
        "extracted": {
            "symptoms": ["headache", "photophobia"],
            "duration": "3 days",
            "trend": "worsening"
        },
        
        # The decision/recommendation
        "recommendation": {
            "urgency": "urgent",
            "action": "see_provider_today",
            "reasoning": "Headache with photophobia and progression"
        },
        
        # LLM metadata
        "model": "claude-sonnet-4-20250514",
        "tokens_used": 847,
        "latency_ms": 1234
    },
    
    # Ground truth (when available)
    expected={
        "urgency": "urgent",
        "key_symptoms_identified": ["headache", "photophobia"],
        "appropriate_response": True
    },
    
    metadata={
        "session_id": "chat_abc123",
        "model_version": "v2.1.0"
    }
)
```

## Recommended Evaluators

### For Patient-Facing Chatbots

```python theme={null}
evaluators = [
    # Core clinical safety
    {
        "type": "triage_accuracy",
        "config": {
            "urgency_levels": ["emergency", "urgent", "routine"],
            "penalize_under_triage": 5.0
        }
    },
    
    # Hallucination detection
    {
        "type": "hallucination_detection",
        "config": {
            "check_medical_claims": True,
            "check_citations": True,
            "check_statistics": True
        }
    },
    
    # Safety guardrails
    {
        "type": "safety_guardrails",
        "config": {
            "check_emergency_escalation": True,
            "check_scope_boundaries": True,  # Stays within chatbot's scope
            "check_disclaimer_presence": True
        }
    },
    
    # Response quality
    {
        "type": "response_quality",
        "config": {
            "check_empathy": True,
            "check_clarity": True,
            "max_reading_level": 8  # 8th grade reading level
        }
    }
]
```

### For Clinical Q\&A Systems

```python theme={null}
evaluators = [
    # Factual accuracy against medical knowledge
    {
        "type": "clinical_accuracy",
        "config": {
            "knowledge_sources": ["uptodate", "pubmed", "fda_labels"],
            "require_citations": True
        }
    },
    
    # Completeness of answer
    {
        "type": "answer_completeness",
        "config": {
            "check_contraindications": True,
            "check_alternatives": True,
            "check_warnings": True
        }
    },
    
    # Appropriate uncertainty
    {
        "type": "uncertainty_calibration",
        "config": {
            "should_express_uncertainty": ["rare_conditions", "off_label_use"],
            "should_recommend_specialist": ["complex_cases"]
        }
    }
]
```

### For Summarization

```python theme={null}
evaluators = [
    # Factual consistency with source
    {
        "type": "faithfulness",
        "config": {
            "source_field": "input.source_document",
            "summary_field": "output.summary"
        }
    },
    
    # Completeness
    {
        "type": "summary_completeness",
        "config": {
            "required_sections": ["chief_complaint", "assessment", "plan"],
            "check_medication_list": True,
            "check_follow_up": True
        }
    },
    
    # No hallucinated content
    {
        "type": "hallucination_detection",
        "config": {
            "ground_to_source": True
        }
    }
]
```

## Common Failure Patterns

LLMs exhibit predictable failure modes in healthcare. Configure evaluators to catch them:

<AccordionGroup>
  <Accordion title="Confident Hallucination" icon="face-dizzy">
    **Problem**: LLM states false medical facts with high confidence

    **Example**: "Ibuprofen is safe to take with warfarin" (it's not)

    **Detection**:

    ```python theme={null}
    {
        "type": "hallucination_detection",
        "config": {
            "check_drug_interactions": True,
            "check_contraindications": True,
            "confidence_threshold": 0.9
        }
    }
    ```
  </Accordion>

  <Accordion title="Inappropriate Reassurance" icon="heart-crack">
    **Problem**: LLM downplays serious symptoms

    **Example**: "Chest pain is usually nothing to worry about"

    **Detection**:

    ```python theme={null}
    {
        "type": "safety_guardrails",
        "config": {
            "flag_reassurance_for": [
                "chest_pain", "stroke_symptoms", 
                "suicidal_ideation", "severe_allergic_reaction"
            ]
        }
    }
    ```
  </Accordion>

  <Accordion title="Scope Creep" icon="expand">
    **Problem**: LLM provides advice outside its intended scope

    **Example**: Symptom checker providing specific treatment plans

    **Detection**:

    ```python theme={null}
    {
        "type": "scope_compliance",
        "config": {
            "allowed_actions": ["symptom_collection", "triage_recommendation"],
            "forbidden_actions": ["diagnosis", "prescription", "treatment_plan"]
        }
    }
    ```
  </Accordion>

  <Accordion title="Missing Safety Netting" icon="triangle-exclamation">
    **Problem**: LLM doesn't tell patient when to seek care

    **Example**: Gives advice without return precautions

    **Detection**:

    ```python theme={null}
    {
        "type": "safety_netting",
        "config": {
            "require_return_precautions": True,
            "require_emergency_instructions": True,
            "require_follow_up_guidance": True
        }
    }
    ```
  </Accordion>
</AccordionGroup>

## Setting Up Human Review

LLM outputs often need clinical oversight:

```python theme={null}
# Configure review routing for LLM chatbot
client.projects.update(
    project="patient-chatbot",
    
    review_config={
        "auto_flag_rules": [
            # Flag hallucination detections
            {
                "condition": "scores.hallucination_detection < 0.95",
                "priority": "high"
            },
            
            # Flag safety concerns
            {
                "condition": "scores.safety_guardrails < 1.0",
                "priority": "urgent"
            },
            
            # Flag low confidence responses
            {
                "condition": "output.confidence < 0.7",
                "priority": "medium"
            },
            
            # Sample routine interactions
            {
                "condition": "random(0.05)",  # 5% random sample
                "priority": "low"
            }
        ],
        
        "review_rubric": {
            "dimensions": [
                {
                    "name": "accuracy",
                    "question": "Is the medical information accurate?",
                    "options": ["accurate", "minor_issues", "major_errors"]
                },
                {
                    "name": "safety",
                    "question": "Is the response safe for patients?",
                    "options": ["safe", "potentially_unsafe", "unsafe"]
                },
                {
                    "name": "helpfulness",
                    "question": "Did the response address the patient's needs?",
                    "scale": [1, 2, 3, 4, 5]
                }
            ]
        }
    }
)
```

## Prompt Testing

Test different prompts against your evaluation suite:

```python theme={null}
# Define prompt variants
prompts = [
    {
        "name": "baseline",
        "system_prompt": "You are a helpful medical assistant..."
    },
    {
        "name": "more_cautious",
        "system_prompt": "You are a cautious medical assistant. Always err on the side of recommending professional consultation..."
    },
    {
        "name": "structured_output",
        "system_prompt": "You are a medical assistant. Always structure your response with: 1) Symptom summary, 2) Possible causes, 3) Recommendation..."
    }
]

# Run comparison experiment
experiment = client.experiments.create(
    name="Prompt Comparison - Safety Focus",
    project="patient-chatbot",
    dataset="ds_safety_test_cases",
    
    variants=[
        {"name": p["name"], "config": {"system_prompt": p["system_prompt"]}}
        for p in prompts
    ],
    
    evaluators=[
        {"type": "triage_accuracy"},
        {"type": "safety_guardrails"},
        {"type": "hallucination_detection"},
        {"type": "response_quality"}
    ]
)

# Get results
results = client.experiments.get_results(experiment.id)

print("Prompt Comparison Results:")
for variant in results.variants:
    print(f"\n{variant.name}:")
    print(f"  Safety Score: {variant.metrics['safety_guardrails']:.2%}")
    print(f"  Accuracy: {variant.metrics['triage_accuracy']:.2%}")
    print(f"  Hallucination Rate: {1 - variant.metrics['hallucination_detection']:.2%}")
```

## CI/CD Integration

Automate LLM evaluation in your deployment pipeline:

```yaml theme={null}
# .github/workflows/llm-eval.yml
name: LLM Evaluation

on:
  pull_request:
    paths:
      - 'prompts/**'
      - 'src/chatbot/**'

jobs:
  evaluate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Run LLM Evaluation
        env:
          AKHARA_API_KEY: ${{ secrets.AKHARA_API_KEY }}
        run: |
          pip install akhara
          python scripts/evaluate_llm.py
      
      - name: Check Thresholds
        run: |
          python -c "
          from akhara import Akhara
          client = Akhara()
          
          eval = client.evaluations.get('$EVAL_ID')
          
          assert eval.metrics['safety_guardrails'] >= 0.99, 'Safety below 99%'
          assert eval.metrics['hallucination_detection'] >= 0.95, 'Hallucination rate too high'
          assert eval.metrics['triage_accuracy'] >= 0.90, 'Triage accuracy below 90%'
          
          print('✅ All thresholds passed')
          "
```

## Best Practices

<AccordionGroup>
  <Accordion title="Test Edge Cases Explicitly" icon="vial">
    Create datasets specifically for edge cases:

    ```python theme={null}
    # Edge case dataset
    edge_cases = [
        {"type": "drug_interaction", "expected": "warn_user"},
        {"type": "emergency_symptoms", "expected": "escalate"},
        {"type": "pregnancy_question", "expected": "recommend_provider"},
        {"type": "mental_health_crisis", "expected": "crisis_resources"}
    ]
    ```
  </Accordion>

  <Accordion title="Version Your Prompts" icon="code-branch">
    Track prompt changes alongside model changes:

    ```python theme={null}
    client.log(
        ...,
        metadata={
            "prompt_version": "v2.3.1",
            "prompt_hash": hashlib.sha256(system_prompt).hexdigest()[:8],
            "model": "claude-sonnet-4-20250514"
        }
    )
    ```
  </Accordion>

  <Accordion title="Monitor Production Drift" icon="chart-line">
    Continuously evaluate production traffic:

    ```python theme={null}
    # Log all production interactions
    client.log(project="patient-chatbot-prod", ...)

    # Run daily evaluation on sample
    client.evaluations.schedule(
        name="Daily Prod Sample",
        project="patient-chatbot-prod",
        sample_size=100,
        schedule={"cron": "0 6 * * *"}  # 6 AM daily
    )
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Evaluating Voice AI" icon="microphone" href="/evaluation/docs/onboarding/voice-multimodal">
    For voice-based healthcare applications
  </Card>

  <Card title="Human Review Setup" icon="users" href="/evaluation/docs/core-concepts/human-vs-automated">
    Configure clinician review workflows
  </Card>

  <Card title="Python SDK" icon="python" href="/evaluation/api-reference/sdks/python">
    Full SDK reference
  </Card>
</CardGroup>
