Crisis Detection โ
SpektraBot includes a multi-layered crisis detection system that identifies when a user is in immediate danger or acute distress and overrides normal SEND guidance with crisis support. This page explains how it works, what it detects, and what happens when it triggers.
Executive Overview โ
What is crisis detection? โ
Sometimes a parent using SpektraBot isn't just frustrated with the SEND system -- they're in genuine crisis. They might mention self-harm, express that they can't go on, or disclose that their child is being hurt. In these moments, SEND advice is not what they need. They need immediate support from trained professionals.
SpektraBot's crisis detection system watches every message for crisis language. When it detects a crisis, it immediately:
- Stops all SEND guidance -- The normal response is replaced entirely
- Validates the person's feelings -- "I can hear that things are incredibly hard right now"
- Provides specific helpline numbers -- Not a generic "seek help", but exact numbers they can call right now
- Leaves the door open -- "I'm here whenever you're ready to come back to the SEND stuff"
What does it detect? โ
The system watches for three categories of crisis:
| Category | Examples | Response |
|---|---|---|
| Self-harm or suicidal ideation | "I want to die", "I can't go on", "better off dead" | Samaritans 116 123, NHS 111, Text SHOUT to 85258 |
| Acute distress | "I can't cope", "I'm at breaking point", "losing my mind" | Contact helpline 0808 808 3555, Samaritans 116 123 |
| Safeguarding concerns | "My child is being hurt", "domestic violence" | 999 if immediate danger, NSPCC 0808 800 5000, local Children's Services |
What about urgent but non-crisis situations? โ
Not everything urgent is a crisis. A parent facing a school exclusion or a tribunal deadline needs fast, practical help -- not crisis helplines. SpektraBot distinguishes between:
- Crisis (safety concern) -- Overrides all guidance, provides helplines
- Urgency (time-sensitive SEND matter) -- Leads with statutory rights and immediate action steps
- Distress (emotional overwhelm) -- Adjusts tone to be more supportive, simplifies advice
Technical Architecture โ
Detection flow โ
Crisis keyword detection โ
The detectCrisisIndicators() function (packages/api/src/services/persona-mapping.service.ts) uses regex pattern matching with word boundaries to prevent false positives:
export function detectCrisisIndicators(message: string): boolean {
const lowerMessage = message.toLowerCase();
const crisisPatterns = [
// Self-harm and suicidal ideation
/\bwant to die\b/,
/\bkill myself\b/,
/\bend my life\b/,
/\bsuicide\b/,
/\bself-harm\b/,
/\bself harm\b/,
/\bhurt myself\b/,
/\bcan't go on\b/,
/\bno point living\b/,
/\bbetter off dead\b/,
/\bwant to hurt myself\b/,
// Acute distress indicators
/\bcan't cope\b/,
/\bcannot cope\b/,
/\bbreaking point\b/,
/\bcan't take anymore\b/,
/\bat my limit\b/,
/\blosing my mind\b/,
// Safeguarding concerns
/\bchild is being hurt\b/,
/\bchild is being abused\b/,
/\bsomeone is hurting my child\b/,
/\bworried about my child's safety\b/,
/\bdomestic abuse\b/,
/\bdomestic violence\b/,
];
return crisisPatterns.some((pattern) => pattern.test(lowerMessage));
}Design decisions:
- Word boundaries (
\b) prevent false positives from substring matching (e.g. "coping" won't trigger "cope") - Case-insensitive via
toLowerCase()before matching - No LLM involvement -- Crisis detection is deterministic and instant, not dependent on model inference latency
Urgency detection (distinct from crisis) โ
The detectUrgencyIndicators() function handles time-sensitive SEND situations that need fast practical help, not crisis intervention:
Exclusion keywords: "excluded", "sent home", "off-roll", "managed move", "permanent exclusion", "suspended"
Deadline keywords: "deadline tomorrow", "tribunal date", "15 days", "response due", "appeal deadline", "running out of time"
Provision breakdown: "school refusing", "won't provide", "no support", "placement broken", "out of school", "missing education"
When urgency (but not crisis) is detected, the system uses the URGENT response mode (100 words max) -- leading with the user's statutory right and one immediate action step.
Crisis prompt override โ
When a crisis is detected, the prompt module service (packages/api/src/services/prompt-module.service.ts) overrides the normal prompt assembly:
if (config.includeCrisis) {
const crisis = await this.getCrisisModule();
if (crisis) {
modules.push(crisis);
// Crisis module overrides role and task modules - return early
return modules.map((m) => m.content).join("\n\n---\n\n");
}
}The assembled prompt becomes: base_core + crisis_response only. The role module (parent/professional), task module (letter writing), and domain modules are all skipped. This ensures the LLM focuses entirely on crisis support.
Crisis response templates โ
The crisis response module (packages/api/src/prompts/modules/crisis_response.md) provides specific templates for each crisis type:
Self-harm / suicidal ideation:
I can hear that things are incredibly hard right now. What you're feeling is real, and you don't have to face this alone.
Please reach out to someone who can help right now:
Samaritans: 116 123 (free, 24/7, won't judge) NHS 111 (select the mental health option) Text SHOUT to 85258 (if you can't talk)
If you're in immediate danger, please call 999.
I'm here to help with SEND support whenever you're ready, but right now the most important thing is that you get the support you need. Is there someone who can be with you?
Child safeguarding concern:
What you've described sounds like a safeguarding concern, and it's important this is reported to people who can help keep your child safe.
If a child is in immediate danger: Call 999
Your local authority Children's Services:
- Search "[Your Local Authority] children's services" for contact numbers
- Most have 24/7 out-of-hours emergency lines
NSPCC Helpline: 0808 800 5000 (if you're not sure whether to report; they can guide you)
You're doing the right thing by being concerned. Professionals are trained to assess these situations properly.
I can help with SEND support once your child's immediate safety is addressed. Is there anything else you need right now?
Acute distress about SEND situation:
I can hear how overwhelming this has become. Navigating the SEND system whilst caring for your child is exhausting, and it's okay to feel like you've hit a wall.
Right now, please be kind to yourself. This is hard.
If you need to talk to someone:
- Samaritans: 116 123 (they listen to anything, not just crisis)
- Contact helpline: 0808 808 3555 (specifically for families with disabled children)
When you're ready, I'm here to help you find a way forward with the SEND stuff. But that can wait until you've had a chance to breathe.
Is there one small thing I could help with right now that might feel manageable?
Crisis response principles โ
The module defines strict rules for crisis responses:
DO:
- Respond immediately and warmly
- Provide specific, concrete contacts (not generic "seek help")
- Validate feelings without agreeing with hopelessness
- Keep the option open to return to SEND support
- Use simple, clear language
DO NOT:
- Continue with SEND guidance before addressing crisis
- Ask probing questions about the crisis details
- Provide advice on the crisis itself (SpektraBot is not qualified)
- Minimise feelings or offer false reassurance
- Leave them without a clear next step
Return to normal flow โ
After a crisis response, if the user indicates they're okay and wants to continue:
"Thank you for letting me know you're okay. I'm glad you've got support. When you're ready, I'm here to help with the SEND situation. No rush."
The system then returns to the appropriate role + intent prompt for subsequent messages.
Conversation intent tracking โ
Crisis detection sets the conversation intent to CRISIS in the database:
enum ConversationIntent {
WAYFINDING
INFORMATION
LETTER_WRITING
CRISIS
}This allows administrators to identify conversations that involved crisis detection and review how the system responded.
Advocate escalation โ
For situations requiring human support, users can escalate to a trained advocate through the Escalate Modal (packages/web/src/components/referral/EscalateModal.tsx):
- Select an available advocate
- Choose urgency level: LOW, NORMAL, HIGH, URGENT
- Provide a reason for escalation
- Consent to data sharing (conversation history, child profile, uploaded documents)
The modal explicitly warns: "If there is a safeguarding concern, the advocate is legally required to report it to the appropriate authorities."
Safeguarding logging โ
When an advocate identifies a safeguarding concern, they can formally log it via the API:
POST /api/advocate/safeguarding
{
"userId": "...",
"childId": "...",
"reportType": "suspected_abuse",
"severityLevel": 3, // 1-4 scale
"details": "..."
}The SafeguardingLog model records:
- Report type and severity (1-4)
- When the Designated Safeguarding Lead was notified (
dslNotifiedAt) - When and if a Local Authority referral was made (
laReferralAt,laReferralRef) - Full audit trail linking to user, child, referral, and advocate
User feedback safety flag โ
Users can also flag concerning AI responses through the feedback system. The safety_concern reason code triggers review:
const VALID_REASON_CODES = [
"confusing",
"too_generic",
"made_me_anxious",
"couldnt_verify",
"doesnt_match_experience",
"didnt_answer",
"dismissive_tone",
"safety_concern", // Triggers review
];Observability and metrics โ
Crisis and urgency detection are tracked via Prometheus metrics:
if (isCrisis) trackCrisisDetected();
if (isUrgent) trackUrgencyDetected();These metrics feed into Grafana dashboards, enabling monitoring of:
- Crisis prevalence across conversations
- Urgency indicator frequency
- Response routing accuracy
Key files โ
| File | Purpose |
|---|---|
packages/api/src/services/persona-mapping.service.ts | Crisis and urgency keyword detection |
packages/api/src/services/prompt-module.service.ts | Prompt assembly with crisis override |
packages/api/src/prompts/modules/crisis_response.md | Crisis response templates and principles |
packages/api/src/prompts/modules/base_core.md | Safety boundaries and escalation rules |
packages/api/src/chat/agentic-rag.ts | Detection integration and metrics tracking |
packages/web/src/components/referral/EscalateModal.tsx | Advocate escalation UI |
packages/api/src/services/advocate/routes.ts | Safeguarding reporting API |
packages/api/prisma/schema.prisma | SafeguardingLog and Referral models |
packages/api/src/services/feedback.service.ts | Safety concern feedback code |
The three-tier safety model โ
In summary: crisis detection is deterministic, instant, and overrides everything. It prioritises human safety over SEND guidance, provides specific UK helpline numbers, and creates an audit trail for review.