Skip to Content
Luna AIGuardrails

Luna AI Guardrails

Luna’s responses pass through a three-layer guardrail system that checks for compliance violations, business rule breaches, and safety issues. The guardrails run after the AI generates a response and can flag, escalate, or block content.

Architecture

AI Response Generated ┌───────────────────┐ │ Compliance Layer │ FDA claims, PHI, clinical, brand voice └────────┬──────────┘ ▼ (parallel) ┌───────────────────┐ │ Business Layer │ Competitors, PII, pricing, prohibited terms └────────┬──────────┘ ▼ (parallel) ┌───────────────────┐ │ Safety Layer │ Dosage limits, drug interactions, contraindications └────────┬──────────┘ ┌───────────────────┐ │ Result Aggregation│ Combine violations, determine severity │ & Escalation │ Log if needed, escalate if critical └───────────────────┘

All three layers run in parallel for performance.

Usage

import { checkGuardrails } from '@loop/guardrails'; const result = await checkGuardrails({ userMessage: 'Can I take 1000mcg of BPC-157?', aiResponse: 'A typical dose of BPC-157 is 250-500mcg...', context: { brandKey: 'loop-rx', userId: 'user_123', userProfile: { conditions: ['hypertension'], medications: ['lisinopril'], biomarkers: [], }, }, }); if (result.shouldEscalate) { // Log escalation, notify staff } for (const violation of result.violations) { console.log(violation.layer); // 'compliance' | 'business' | 'safety' console.log(violation.type); // e.g., 'fda_claim', 'dosage_exceeded' console.log(violation.severity); // 'info' | 'warning' | 'critical' console.log(violation.message); // Human-readable description }

Compliance Layer

Checks for FDA regulatory compliance, PHI exposure, clinical safety, and brand voice consistency.

FDA Compliance

Detects responses that make unapproved claims about peptides or supplements:

PatternViolation
”FDA approved for…”False FDA approval claim
”Cures [condition]“Unapproved cure claim
”Guaranteed to…”Efficacy guarantee
”Prescribing [medication]“Unauthorized prescribing
Diagnosing conditionsUnauthorized diagnosis

PHI Protection

Detects potential Protected Health Information in responses:

PatternType
SSN patternsphi_exposure
Medical record numbersphi_exposure
Patient ID exposurephi_exposure
Date of birthphi_exposure
Insurance informationphi_exposure

Clinical Safety

PatternViolation
Recommending specific prescriptionsclinical_violation
Suggesting medication adjustmentsclinical_violation
Making direct diagnosesclinical_violation
Mentioning controlled substances without disclaimerclinical_violation
Emergency without 911 guidanceclinical_violation

Brand Voice

PatternViolation
Overly casual medical advicebrand_violation
Dismissing emergenciesbrand_violation
Absolute medical statementsbrand_violation
Missing medical disclaimersbrand_violation

Business Layer

Checks for business rule compliance including competitor mentions, PII exposure, and pricing violations.

Competitor Detection

Luna should not recommend or compare against competitors:

Blocked competitors: Hims, Hers, Ro, Roman, Numan, Keeps, Nurx, Empower Pharmacy, Tailor Made, Defy Medical, Marek Health, Ways2Well

PII Protection

Detects personally identifiable information in responses:

PatternType
Email addressespii_exposure
Phone numberspii_exposure
Physical addressespii_exposure
ZIP codespii_exposure
Credit card numberspii_exposure

Pricing Rules

PatternViolation
Mentioning specific pricespricing_violation
Offering discountspricing_violation
Price comparisonspricing_violation

Prohibited Terms

Certain terms trigger business violations:

  • “wholesale price”
  • “bulk discount”
  • “gray market”
  • “counterfeit”
  • Other terms that could create legal liability

Safety Layer

Checks for dosage safety, drug interactions, and contraindications.

Dosage Limits

Maximum recommended dosages for common peptides:

PeptideMax Single DoseMax Daily Dose
BPC-157500mcg1000mcg
TB-5005mg10mg
Ipamorelin300mcg900mcg
CJC-12952mg2mg
MK-67725mg25mg
Semaglutide2.4mg2.4mg

If the AI response mentions a dosage exceeding these limits, a dosage_exceeded violation is raised.

Drug Interactions

Known peptide-drug interactions checked:

PeptideInteracting DrugSeverity
BPC-157Anticoagulants (warfarin, heparin)Moderate
IpamorelinInsulin, MetforminModerate
MK-677Insulin, Diabetes medicationsHigh
SemaglutideInsulin, SulfonylureasHigh

Contraindication Integration

Uses @loop/contraindications and @loop/health-data to check the AI response against the patient’s conditions and medications.

Brand Configuration

Guardrails are configurable per brand using the Loop brand config:

// packages/guardrails/src/config/brands/loop.ts export const loopConfig: BrandGuardrailConfig = { compliance: { fdaPatterns: [...], phiPatterns: [...], clinicalPatterns: [...], brandVoicePatterns: [...], }, business: { competitorPatterns: [...], piiPatterns: [...], pricingPatterns: [...], prohibitedTerms: [...], }, safety: { dosageLimits: [...], drugInteractions: [...], }, };

Severity Levels

SeverityActionExample
infoLog onlyMinor brand voice inconsistency
warningLog + flagCompetitor mention, borderline dosage
criticalLog + escalatePHI exposure, dangerous dosage, emergency mishandling

Guardrail Result

interface GuardrailResult { passed: boolean; // No critical violations shouldEscalate: boolean; // Requires human review violations: Violation[]; summary: string; // Human-readable summary }