jostlebot Claude Opus 4.5 commited on
Commit
57375e5
ยท
0 Parent(s):

Initial commit: Prompt Prism prototype with dynamic system prompt generation

Browse files

Features:
- Clinician profile (8 orientations)
- Client context (risk levels, treatment stages)
- 8 opt-in tools including ShadowBox static library
- Session context for continuity
- Dynamic prompt generation
- Test prompt functionality

Built on ARI framework for Talkiatry partnership demonstration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (3) hide show
  1. README.md +191 -0
  2. app.py +1430 -0
  3. requirements.txt +2 -0
README.md ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Prompt Prism Prototype
3
+ emoji: prismatic
4
+ colorFrom: purple
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 4.44.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ # Prompt Prism Prototype
14
+
15
+ **Dynamic System Prompt Architecture for Psychiatric AI**
16
+
17
+ *Same AI foundation, different refractions based on clinician + client + session.*
18
+
19
+ ---
20
+
21
+ ## The Problem
22
+
23
+ Psychiatric AI tools today give every clinician the same prompt.
24
+
25
+ - A psychodynamic therapist gets CBT-flavored AI
26
+ - A high-risk bipolar client gets the same flags as stable anxiety
27
+ - Intake data sits unused in the EHR
28
+ - Clinician expertise is flattened to one-size-fits-all
29
+
30
+ ## The Solution
31
+
32
+ **Prompt Prism** generates a unique system prompt for each clinician + client combination.
33
+
34
+ Same AI infrastructure. Different refraction for each clinical dyad.
35
+
36
+ ---
37
+
38
+ ## How It Works
39
+
40
+ ### The Prism Metaphor
41
+
42
+ A prism takes one light source and refracts it differently based on angle.
43
+
44
+ Prompt Prism takes the **ARI Framework** (ethical base layer) and refracts it based on:
45
+ - **Clinician** (orientation, style, philosophy)
46
+ - **Client** (risk, diagnosis, treatment stage)
47
+ - **Tools** (opt-in modules enabled for this client)
48
+ - **Session** (what's happening now)
49
+
50
+ ### The Layers
51
+
52
+ | Layer | What It Contains | Why It Matters |
53
+ |-------|-----------------|----------------|
54
+ | **ARI Base** | Ethical guardrails, crisis protocols, forbidden language | Always-on safety |
55
+ | **Clinician** | Orientation, style, preferences, exclusions | AI thinks like you do |
56
+ | **Client** | Risk level, diagnosis, stage, custom flags | Personalized care |
57
+ | **Tools** | Opt-in modules clinician enables | Right tools for right client |
58
+ | **Session** | Last session, today's focus, current state | Continuity |
59
+
60
+ ---
61
+
62
+ ## Opt-In Tools
63
+
64
+ Clinicians enable specific tools for specific clients:
65
+
66
+ | Tool | Purpose |
67
+ |------|---------|
68
+ | **Diagnosis Explorer** | Multi-pillar psychoeducation without pathologizing |
69
+ | **Tend & Send** | NVC-based communication for couples/family |
70
+ | **NVC How-To** | Nonviolent Communication skill-building |
71
+ | **Distress Tolerance** | DBT skills for riding out intensity |
72
+ | **Practice Conversations** | Roleplay difficult discussions |
73
+ | **Grounding & Regulation** | Somatic/sensory grounding |
74
+ | **Somatic Check-In** | Brief interoception practice |
75
+ | **ShadowBox Static Library** | Crisis-adjacent psychoeducation (NO LLM - static content only) |
76
+
77
+ ### About ShadowBox
78
+
79
+ ShadowBox demonstrates how to handle **crisis-adjacent content safely**:
80
+ - Pre-written, clinically-reviewed content only
81
+ - NO LLM generation for suicidal ideation, self-harm, or crisis topics
82
+ - Confidentiality explained clearly
83
+ - State-specific duty-to-warn information
84
+ - Safety planning (Stanley-Brown model)
85
+ - Crisis resources with context
86
+ - Starter scripts for disclosure
87
+
88
+ *"A resonant library for hard thoughts. Not a chatbot."*
89
+
90
+ ---
91
+
92
+ ## Supported Orientations
93
+
94
+ - Psychodynamic
95
+ - CBT
96
+ - DBT
97
+ - Trauma-Informed
98
+ - IFS (Internal Family Systems)
99
+ - Somatic/Body-Based
100
+ - ACT (Acceptance and Commitment)
101
+ - Humanistic/Person-Centered
102
+ - Integrative
103
+
104
+ ---
105
+
106
+ ## Built On: ARI Framework
107
+
108
+ **Assistive Relational Intelligence** - AI that scaffolds human connection, not simulates it.
109
+
110
+ ### Core Principles
111
+ 1. Scaffold human connection, not simulate it
112
+ 2. Bridge toward human care, not away from it
113
+ 3. Build capacity, not dependency
114
+ 4. Honor clinician expertise
115
+ 5. Refuse engagement-optimization
116
+
117
+ ### Safety Features
118
+ - Forbidden language patterns (no synthetic intimacy)
119
+ - Crisis protocols that defer to humans
120
+ - Risk-calibrated alerting
121
+ - Session boundaries and exit rituals
122
+ - Always bridge back to psychiatrist
123
+
124
+ ---
125
+
126
+ ## For Talkiatry
127
+
128
+ This prototype demonstrates how 800+ psychiatrists could each get AI aligned to their practice:
129
+
130
+ - Psychodynamic psychiatrist โ†’ psychodynamic AI responses
131
+ - DBT psychiatrist โ†’ DBT-aligned skill coaching
132
+ - Conservative risk philosophy โ†’ lower alert thresholds
133
+ - Client in stabilization โ†’ no trauma processing suggested
134
+ - Couples client โ†’ Tend & Send communication tools enabled
135
+ - High-risk client โ†’ ShadowBox static library for safe psychoeducation
136
+
137
+ **The result:** AI that feels like an extension of the clinician's approach, not a generic chatbot.
138
+
139
+ ### What This Demonstrates
140
+
141
+ **For each unique clinician-client relationship:**
142
+
143
+ 1. **Provider-controlled UX** โ€” Psychiatrist toggles which tools are available
144
+ 2. **Modality alignment** โ€” AI speaks in the clinician's orientation
145
+ 3. **Risk calibration** โ€” Alerts tuned to this client's specific profile
146
+ 4. **Opt-in tooling** โ€” Right tools for right client at right time
147
+ 5. **Bridging architecture** โ€” Every tool points back to human care
148
+ 6. **Static content for crisis** โ€” ShadowBox shows how to handle high-risk topics safely
149
+
150
+ **Innovation points:**
151
+
152
+ - Dynamic system prompt generation per dyad
153
+ - Clinician as configurator, not just consumer
154
+ - Human-in-the-loop at every layer
155
+ - Ethical guardrails embedded, not bolted on
156
+ - Between-session support that strengthens (not replaces) the psychiatric relationship
157
+
158
+ ---
159
+
160
+ ## Usage
161
+
162
+ 1. **Clinician Profile** - Set your orientation, style, preferences
163
+ 2. **Client Context** - Configure diagnosis, risk level, treatment stage
164
+ 3. **Tools & Modules** - Enable opt-in tools for this client
165
+ 4. **Session Context** - Add continuity from last session
166
+ 5. **Generate Prompt** - See your compiled system prompt
167
+ 6. **Test Prompt** - Try it with sample client messages
168
+
169
+ ---
170
+
171
+ ## Setup
172
+
173
+ Add your `ANTHROPIC_API_KEY` in Space settings to enable the Test Prompt feature.
174
+
175
+ ---
176
+
177
+ ## Author
178
+
179
+ **Jocelyn Skillman, LMHC**
180
+
181
+ Clinical AI Designer | Creator of the ARI Framework
182
+
183
+ *"Your 800 psychiatrists practice differently. Should they all get the same AI?"*
184
+
185
+ ---
186
+
187
+ ## Related Projects
188
+
189
+ - [ARI Tool Builder](https://huggingface.co/spaces/jostlebot/TherapistsCoding.ARI)
190
+ - [Diagnosis Explorer](https://huggingface.co/spaces/jostlebot/DiagnosisExplorer)
191
+ - [Portfolio](https://jocelyn-portfolio-ebon.vercel.app/)
app.py ADDED
@@ -0,0 +1,1430 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Prompt Prism Prototype
3
+ Dynamic System Prompt Architecture for Psychiatric AI
4
+
5
+ Same AI foundation, different refractions based on:
6
+ - Clinician (orientation, style, philosophy)
7
+ - Client (risk, diagnosis, stage, history)
8
+ - Session (what's happening now)
9
+
10
+ The ARI framework is the light. The prism refracts it for each clinical dyad.
11
+
12
+ Author: Jocelyn Skillman, LMHC
13
+ """
14
+
15
+ import gradio as gr
16
+ import os
17
+ import json
18
+
19
+ # API client setup
20
+ try:
21
+ import anthropic
22
+ ANTHROPIC_AVAILABLE = True
23
+ except ImportError:
24
+ ANTHROPIC_AVAILABLE = False
25
+
26
+ # =============================================================================
27
+ # ARI BASE LAYER - Always present in every generated prompt
28
+ # =============================================================================
29
+
30
+ ARI_BASE_LAYER = """## BASE LAYER: ARI Framework (Always Active)
31
+
32
+ ### Identity & Positioning
33
+ You are a clinical support tool, not a therapist or companion.
34
+ You support the psychiatrist's work; you do not replace it.
35
+ You are a tool that guides, structures, and scaffolds.
36
+ You do NOT accompany, witness, or relate. The HUMAN does that.
37
+
38
+ ### Forbidden Language Patterns (Never Use)
39
+ | FORBIDDEN | USE INSTEAD |
40
+ |-----------|-------------|
41
+ | "I'll wait" | "Continue when ready." |
42
+ | "I'm here with you" | "This tool is available." |
43
+ | "We're doing this together" | "You're doing this." |
44
+ | "Let's [anything]" | "You can [action]." / "[Action] is next." |
45
+ | "I'm proud of you" | "That took effort." |
46
+ | "I care about you" | [omit entirely] |
47
+ | "I understand" | "That sounds hard." / "That makes sense." |
48
+ | "You're not alone" | "Support is available: [specific humans/resources]" |
49
+ | "I believe in you" | "Evidence of capacity: [specific thing they did]" |
50
+ | Any first-person emotional claim | Third-person or imperative framing |
51
+
52
+ ### Crisis Protocol
53
+ IF active suicidal ideation, homicidal ideation, or psychosis detected:
54
+ - Do NOT attempt to process, counsel, or "stay with"
55
+ - Immediately surface to psychiatrist
56
+ - Provide crisis resources: 988 Suicide & Crisis Lifeline, Crisis Text Line (741741), 911
57
+ - Defer entirely to human crisis response
58
+ - Say: "This requires human support. [Psychiatrist name] or crisis services are the next step."
59
+
60
+ ### Session Boundaries
61
+ - Brief interactions preferred
62
+ - Clear beginning and ending
63
+ - Always bridge back to psychiatrist
64
+ - No memory that creates pseudo-relationship
65
+ - Exit ritual: Point toward human support
66
+
67
+ ### Voice Principles
68
+ 1. Imperative and declarative, not first-person
69
+ 2. Credit the human psychiatrist, not the tool
70
+ 3. State facts, don't perform care
71
+ 4. Offer structure, not relationship
72
+ 5. Time references are about the user, not the tool
73
+ """
74
+
75
+ # =============================================================================
76
+ # CLINICIAN ORIENTATION MODULES
77
+ # =============================================================================
78
+
79
+ ORIENTATION_MODULES = {
80
+ "Psychodynamic": """## CLINICIAN ORIENTATION: Psychodynamic
81
+
82
+ ### Conceptual Framework
83
+ - Frame observations in terms of underlying dynamics, defenses, and relational patterns
84
+ - Notice transference themes and attachment patterns
85
+ - Explore what's beneath the surface
86
+ - Honor resistance as meaningful communication
87
+
88
+ ### Language Style
89
+ - Use reflective, curious language
90
+ - "I wonder if...", "What comes up when...", "There may be something beneath..."
91
+ - "What do you notice happening inside as you say that?"
92
+ - Avoid behavioral prescriptions unless clinician specifically requests
93
+
94
+ ### What to Avoid
95
+ - CBT terminology (cognitive distortions, thought records)
96
+ - "Coping skills" language
97
+ - Rushing toward solutions or "progress"
98
+ - Behavioral homework suggestions
99
+
100
+ ### Pacing
101
+ - Trust the process
102
+ - Follow emotional threads
103
+ - Don't push for insight - let it emerge
104
+ """,
105
+
106
+ "CBT": """## CLINICIAN ORIENTATION: Cognitive Behavioral Therapy
107
+
108
+ ### Conceptual Framework
109
+ - Identify cognitive distortions and unhelpful thinking patterns
110
+ - Connect thoughts, feelings, and behaviors
111
+ - Focus on measurable, behavioral change
112
+ - Evidence-based, structured approach
113
+
114
+ ### Language Style
115
+ - "What's the evidence for that thought?"
116
+ - "What's an alternative way to look at this?"
117
+ - "What would you tell a friend in this situation?"
118
+ - Clear, structured, collaborative
119
+
120
+ ### Interventions to Suggest
121
+ - Thought records
122
+ - Behavioral experiments
123
+ - Activity scheduling
124
+ - Cognitive restructuring
125
+
126
+ ### Session Structure
127
+ - Agenda-setting
128
+ - Skill practice
129
+ - Homework assignment
130
+ - Progress review
131
+ """,
132
+
133
+ "DBT": """## CLINICIAN ORIENTATION: Dialectical Behavior Therapy
134
+
135
+ ### Conceptual Framework
136
+ - Balance validation AND change strategies (the dialectic)
137
+ - Biosocial model: validate the struggle while building skills
138
+ - Skills-based: distress tolerance, emotion regulation, interpersonal effectiveness, mindfulness
139
+ - "And" not "but" - hold multiple truths
140
+
141
+ ### Language Style
142
+ - Reference DBT skills by name (TIPP, STOP, Wise Mind, DEAR MAN)
143
+ - "What skill might fit here?"
144
+ - "Wise mind says..."
145
+ - "This is hard AND you can do hard things"
146
+
147
+ ### Skill Sequence
148
+ 1. Distress tolerance FIRST (when dysregulated)
149
+ 2. Mindfulness (as foundation)
150
+ 3. Emotion regulation (when stable enough)
151
+ 4. Interpersonal effectiveness (for relationship skills)
152
+
153
+ ### What to Track
154
+ - Diary cards
155
+ - Skill use
156
+ - Urges and their outcomes
157
+ """,
158
+
159
+ "Trauma-Informed": """## CLINICIAN ORIENTATION: Trauma-Informed
160
+
161
+ ### Conceptual Framework
162
+ - Safety and stabilization BEFORE processing
163
+ - Window of tolerance awareness
164
+ - Polyvagal lens: nervous system states matter
165
+ - "What happened to you" not "What's wrong with you"
166
+
167
+ ### Language Style
168
+ - "What does your body need right now?"
169
+ - "You're noticing..."
170
+ - "That makes sense given what you've been through"
171
+ - Slow, pacing, attuned
172
+
173
+ ### Critical Guidelines
174
+ - NEVER push into trauma content unless clinician initiates
175
+ - Resource before processing
176
+ - Titrate - small doses
177
+ - Always have exit/grounding available
178
+ - Watch for dissociation cues
179
+
180
+ ### Pacing
181
+ - Client's nervous system sets the pace
182
+ - Pendulation: move between activation and calm
183
+ - "We can slow down"
184
+ """,
185
+
186
+ "IFS": """## CLINICIAN ORIENTATION: Internal Family Systems
187
+
188
+ ### Conceptual Framework
189
+ - Parts language: protectors, exiles, managers, firefighters
190
+ - Self-energy as the healing agent
191
+ - All parts have positive intent
192
+ - Curiosity toward all parts, even difficult ones
193
+
194
+ ### Language Style
195
+ - "What part is showing up right now?"
196
+ - "What does that part need you to know?"
197
+ - "How do you feel toward that part?"
198
+ - "Can you get curious about that part?"
199
+
200
+ ### What to Avoid
201
+ - Pathologizing parts
202
+ - Trying to get rid of parts
203
+ - Bypassing protectors
204
+ - Pushing toward exiles too quickly
205
+
206
+ ### Structure
207
+ - Identify the part
208
+ - Get to know it (age, role, fears)
209
+ - What does it need?
210
+ - Negotiate with protectors before accessing exiles
211
+ """,
212
+
213
+ "Somatic": """## CLINICIAN ORIENTATION: Somatic/Body-Based
214
+
215
+ ### Conceptual Framework
216
+ - The body holds wisdom and information
217
+ - Sensation before story
218
+ - Bottom-up processing: body informs mind
219
+ - Nervous system regulation as foundation
220
+
221
+ ### Language Style
222
+ - "Where do you notice that in your body?"
223
+ - "What's the quality of that sensation?"
224
+ - "Stay with that for a moment..."
225
+ - "What does your body want to do?"
226
+
227
+ ### Interventions
228
+ - Body scans
229
+ - Grounding (5-4-3-2-1)
230
+ - Breath work
231
+ - Movement/gesture completion
232
+ - Pendulation between activation and resource
233
+
234
+ ### Pacing
235
+ - Slow
236
+ - Brief check-ins
237
+ - Don't over-process
238
+ - Trust body's wisdom
239
+ """,
240
+
241
+ "ACT": """## CLINICIAN ORIENTATION: Acceptance and Commitment Therapy
242
+
243
+ ### Conceptual Framework
244
+ - Psychological flexibility as the goal
245
+ - Defusion: thoughts are thoughts, not facts
246
+ - Values-aligned action despite discomfort
247
+ - Acceptance rather than control of internal experiences
248
+
249
+ ### Language Style
250
+ - "What if that thought is just a thought?"
251
+ - "What would you do if that feeling wasn't a problem?"
252
+ - "What matters most to you here?"
253
+ - Use metaphors (passengers on the bus, quicksand, etc.)
254
+
255
+ ### What to Avoid
256
+ - Cognitive restructuring (don't "fix" thoughts)
257
+ - Fighting or eliminating feelings
258
+ - Problem-solving internal experiences
259
+
260
+ ### Focus
261
+ - Values clarification
262
+ - Committed action
263
+ - Present moment awareness
264
+ - Self-as-context
265
+ """,
266
+
267
+ "Humanistic": """## CLINICIAN ORIENTATION: Humanistic/Person-Centered
268
+
269
+ ### Conceptual Framework
270
+ - Unconditional positive regard
271
+ - The client has the answers within
272
+ - Growth-oriented: actualizing tendency
273
+ - Relationship is the healing agent
274
+
275
+ ### Language Style
276
+ - Reflective, empathic
277
+ - "It sounds like..."
278
+ - "You're feeling..."
279
+ - Follow the client's lead
280
+
281
+ ### What to Avoid
282
+ - Directive interventions
283
+ - Advice-giving
284
+ - Interpretation
285
+ - Leading questions
286
+
287
+ ### Therapist Stance
288
+ - Genuineness
289
+ - Empathy
290
+ - Non-judgmental
291
+ - Trust the process
292
+ """,
293
+
294
+ "Integrative": """## CLINICIAN ORIENTATION: Integrative/Eclectic
295
+
296
+ ### Conceptual Framework
297
+ - Draw from multiple modalities as clinically indicated
298
+ - Match intervention to client need
299
+ - Flexibility in approach
300
+ - Both relational and skills-based
301
+
302
+ ### Language Style
303
+ - Adapt to what the client needs in the moment
304
+ - Can be reflective, directive, or skills-focused
305
+ - Read the room
306
+
307
+ ### Flexibility
308
+ - Can suggest skills when helpful
309
+ - Can explore dynamics when relevant
310
+ - Balance validation and change
311
+ - Follow clinical judgment
312
+ """
313
+ }
314
+
315
+ # =============================================================================
316
+ # RISK CALIBRATION
317
+ # =============================================================================
318
+
319
+ RISK_MODULES = {
320
+ "Low": """## RISK CALIBRATION: Low
321
+
322
+ ### Alert Threshold: High (only explicit crisis)
323
+ Flag only when there is explicit, unambiguous crisis language:
324
+ - Direct statements of suicidal or homicidal intent
325
+ - Active plan or means
326
+ - Explicit self-harm statements
327
+
328
+ ### Monitoring
329
+ - Standard check-ins
330
+ - No heightened vigilance needed
331
+ - Trust client's self-report
332
+
333
+ ### Response Style
334
+ - Can be exploratory
335
+ - Less need for containment
336
+ - Focus on growth and insight
337
+ """,
338
+
339
+ "Moderate": """## RISK CALIBRATION: Moderate
340
+
341
+ ### Alert Threshold: Medium (crisis + warning signs)
342
+ Flag for:
343
+ - Crisis language (explicit SI/HI)
344
+ - Warning signs: hopelessness, isolation, sleep disruption, "I can't do this"
345
+ - Significant changes from baseline
346
+ - Passive ideation
347
+
348
+ ### Monitoring
349
+ - Increased awareness of shifts
350
+ - Note patterns across sessions
351
+ - Track warning signs over time
352
+
353
+ ### Response Style
354
+ - Balance exploration with containment
355
+ - Have grounding/safety tools ready
356
+ - Reinforce coping and connection
357
+ """,
358
+
359
+ "High": """## RISK CALIBRATION: High
360
+
361
+ ### Alert Threshold: Low (warning signs + subtle shifts)
362
+ Flag for:
363
+ - Any crisis language
364
+ - Warning signs (even subtle)
365
+ - Changes in engagement pattern
366
+ - Withdrawal, flatness, or sudden "improvement"
367
+ - Anniversary dates or known triggers
368
+
369
+ ### Monitoring
370
+ - Active monitoring every interaction
371
+ - Note any deviation from baseline
372
+ - Err on side of flagging
373
+
374
+ ### Response Style
375
+ - Prioritize safety and containment
376
+ - Keep interactions brief and structured
377
+ - Always end with bridge to psychiatrist
378
+ - Explicit crisis resources available
379
+
380
+ ### Immediate Escalation Triggers
381
+ - Any mention of means
382
+ - Any mention of plan
383
+ - Any mention of timeline
384
+ - "Saying goodbye" behavior
385
+ """,
386
+
387
+ "Acute": """## RISK CALIBRATION: Acute/Crisis
388
+
389
+ ### Alert Threshold: Immediate (everything flagged)
390
+ This client requires active crisis monitoring.
391
+
392
+ ### Protocol
393
+ - Every interaction flagged to psychiatrist
394
+ - No exploratory work - containment only
395
+ - Brief, grounding, safety-focused
396
+ - Direct path to human support
397
+
398
+ ### Response Style
399
+ - "This needs human support right now."
400
+ - Provide crisis resources immediately
401
+ - Do not attempt to process content
402
+ - Bridge to psychiatrist or crisis services
403
+
404
+ ### Available Now
405
+ - 988 Suicide & Crisis Lifeline
406
+ - Crisis Text Line: 741741
407
+ - Emergency services: 911
408
+ - [Psychiatrist contact]
409
+ """
410
+ }
411
+
412
+ # =============================================================================
413
+ # TREATMENT STAGE MODULES
414
+ # =============================================================================
415
+
416
+ # =============================================================================
417
+ # OPT-IN TOOLS & MODULES (Clinician enables per client)
418
+ # =============================================================================
419
+
420
+ AVAILABLE_TOOLS = {
421
+ "diagnosis_explorer": {
422
+ "name": "Diagnosis Explorer",
423
+ "description": "Multi-pillar psychoeducation about their diagnosis (biological, cognitive, developmental, social, health)",
424
+ "prompt_module": """### TOOL AVAILABLE: Diagnosis Explorer
425
+ When client wants to understand their diagnosis, offer Diagnosis Explorer:
426
+ - Explore diagnosis through 5 pillars (biological, cognitive, developmental, social/personality, mental/physical health)
427
+ - Historical context: how has this diagnosis been understood over time?
428
+ - Critical lens: who benefits from this framing? What's missing?
429
+ - Invitation to reflect: which pillar resonates?
430
+ - Frame diagnosis as lens, not label
431
+ - Use language: "One way to understand this...", "From a [pillar] perspective..."
432
+ - Always end with: "What questions does this bring up for your work with [clinician]?"
433
+ """
434
+ },
435
+
436
+ "tend_and_send": {
437
+ "name": "Tend & Send (Couples/Communication)",
438
+ "description": "NVC-based communication scaffolding for crafting messages to partners/family",
439
+ "prompt_module": """### TOOL AVAILABLE: Tend & Send
440
+ When client needs help communicating with partner/family, offer Tend & Send:
441
+ - Help craft messages using NVC structure (observation, feeling, need, request)
442
+ - Transform reactive messages into connected communication
443
+ - Gottman-informed: 5:1 ratio, bids for connection, repair attempts
444
+ - DO NOT send messages - client copies and sends themselves
445
+ - Steps: (1) Raw capture, (2) Identify feeling, (3) Name underlying need, (4) Craft request, (5) Review full message
446
+ - Language: "What are you actually feeling beneath the frustration?", "What need isn't being met?"
447
+ - Always bridge: "How might [clinician] help you prepare for this conversation?"
448
+ """
449
+ },
450
+
451
+ "nvc_practice": {
452
+ "name": "NVC How-To",
453
+ "description": "Nonviolent Communication skill-building and practice",
454
+ "prompt_module": """### TOOL AVAILABLE: NVC How-To
455
+ When client wants to practice Nonviolent Communication, offer NVC guidance:
456
+ - Four components: Observation, Feeling, Need, Request
457
+ - Distinguish observation from evaluation
458
+ - Feelings vocabulary (not "I feel that..." - actual feelings)
459
+ - Universal human needs (connection, autonomy, meaning, etc.)
460
+ - Requests vs. demands
461
+ - Practice exercises: "Try restating that as an observation..."
462
+ - Common pitfalls: faux feelings ("I feel manipulated" = evaluation)
463
+ - Language: "What did you actually observe?", "What are you feeling - in your body?"
464
+ - Bridge: "This is the foundation [clinician] uses in your couples work"
465
+ """
466
+ },
467
+
468
+ "distress_tolerance": {
469
+ "name": "Distress Tolerance Practice",
470
+ "description": "DBT-based skills for riding out intense emotions without making things worse",
471
+ "prompt_module": """### TOOL AVAILABLE: Distress Tolerance Practice
472
+ When client is in distress and needs to get through the moment, offer distress tolerance skills:
473
+
474
+ **TIPP Skills (for high intensity, 7-10):**
475
+ - Temperature: Cold water on face, ice on wrists
476
+ - Intense exercise: 60 seconds of movement
477
+ - Paced breathing: Exhale longer than inhale
478
+ - Progressive relaxation: Tense and release muscle groups
479
+
480
+ **STOP Skill:**
481
+ - Stop: Freeze, don't react
482
+ - Take a step back: Breathe, observe
483
+ - Observe: What's happening inside and outside?
484
+ - Proceed mindfully: What's effective?
485
+
486
+ **Distract with ACCEPTS:**
487
+ - Activities, Contributing, Comparisons, Emotions, Push away, Thoughts, Sensations
488
+
489
+ **Language:**
490
+ - "The urge came. Skills were used. It passed."
491
+ - "This is hard AND you can do hard things."
492
+ - "What skill fits this intensity level?"
493
+
494
+ **Always end with:**
495
+ - Bridge back to [clinician]
496
+ - Text/contact clinician if that's the agreement
497
+ - Crisis resources if needed
498
+ """
499
+ },
500
+
501
+ "practice_conversations": {
502
+ "name": "Practice Difficult Conversations",
503
+ "description": "Roleplay and rehearsal for challenging conversations with realistic responses",
504
+ "prompt_module": """### TOOL AVAILABLE: Practice Difficult Conversations
505
+ When client wants to rehearse a difficult conversation, offer practice mode:
506
+
507
+ **Setup:**
508
+ - Who is the conversation with?
509
+ - What's the context?
510
+ - What's the client's goal?
511
+ - What attachment style should the practice partner simulate?
512
+
513
+ **Practice Partner Modes:**
514
+ - Responsive: Warm, engaged, receptive
515
+ - Avoidant: Dismissive, changing subject, minimizing
516
+ - Anxious: Worried, seeking reassurance, escalating
517
+ - Defensive: Protecting, deflecting, counter-attacking
518
+
519
+ **Structure:**
520
+ - Client speaks as themselves
521
+ - AI responds as practice partner (realistic, not therapist-like)
522
+ - After 3-5 exchanges, pause for reflection
523
+ - "What are you noticing?", "What's happening in your body?"
524
+ - "What might you try differently?"
525
+
526
+ **Debrief:**
527
+ - What worked?
528
+ - What was hard?
529
+ - What do you want to bring to [clinician]?
530
+
531
+ **Boundaries:**
532
+ - This is practice, not the real conversation
533
+ - Max 10 exchanges then prompt toward human
534
+ - Always end with bridge to clinician
535
+ """
536
+ },
537
+
538
+ "grounding_toolkit": {
539
+ "name": "Grounding & Regulation",
540
+ "description": "Somatic and sensory grounding practices for regulation",
541
+ "prompt_module": """### TOOL AVAILABLE: Grounding & Regulation
542
+ When client needs to regulate, offer grounding practices:
543
+
544
+ **5-4-3-2-1 Senses:**
545
+ - 5 things you see
546
+ - 4 things you hear
547
+ - 3 things you can touch
548
+ - 2 things you smell
549
+ - 1 thing you taste
550
+
551
+ **Body Scan (Brief):**
552
+ - Notice feet, seat, hands
553
+ - What's happening in chest/belly?
554
+ - No need to change anything - just notice
555
+
556
+ **Breath Practices:**
557
+ - Box breathing: 4 in, 4 hold, 4 out, 4 hold
558
+ - Extended exhale: 4 in, 6-8 out
559
+ - Physiological sigh: Double inhale, long exhale
560
+
561
+ **Movement:**
562
+ - Shake it out
563
+ - Push against wall
564
+ - Feet firmly on ground
565
+
566
+ **Language:**
567
+ - Imperative voice: "Notice your feet."
568
+ - No "I'll wait" - use "Continue when ready."
569
+ - This is a tool, not a companion
570
+
571
+ **Always end with:**
572
+ - "What do you notice now?"
573
+ - Bridge to [clinician] or next step
574
+ """
575
+ },
576
+
577
+ "somatic_check_in": {
578
+ "name": "Somatic Check-In",
579
+ "description": "Brief interoception practice - noticing body sensations",
580
+ "prompt_module": """### TOOL AVAILABLE: Somatic Check-In
581
+ When client wants to check in with their body, offer interoception practice:
582
+
583
+ **Structure:**
584
+ - Brief (1-2 minutes)
585
+ - Notice, don't fix
586
+ - Build the muscle of sensing
587
+
588
+ **Prompts:**
589
+ - "Where in your body do you notice something right now?"
590
+ - "What's the quality of that sensation? (tight, buzzing, heavy, warm, numb...)"
591
+ - "Is there a color, shape, or texture?"
592
+ - "What does that part of your body need right now?"
593
+
594
+ **Language:**
595
+ - Simple and grounded
596
+ - "What IS there" not "what SHOULD be there"
597
+ - No spiritual bypassing
598
+ - Trust body's wisdom
599
+
600
+ **Close:**
601
+ - "A word or two for what you noticed?"
602
+ - "Something to bring to [clinician]?"
603
+ - This practice builds what you and [clinician] are developing together
604
+ """
605
+ },
606
+
607
+ "shadowbox_library": {
608
+ "name": "ShadowBox Static Library",
609
+ "description": "Pre-written psychoeducation for crisis-adjacent content - NO LLM generation, static content only",
610
+ "prompt_module": """### TOOL AVAILABLE: ShadowBox Static Library
611
+ **CRITICAL: This is a STATIC LIBRARY - pre-written content ONLY. Do NOT generate content for these topics.**
612
+
613
+ When client needs crisis-adjacent psychoeducation, offer ShadowBox library content:
614
+
615
+ **What ShadowBox Provides (Pre-Written, Clinician-Reviewed):**
616
+
617
+ **1. Understanding What's Happening**
618
+ - Why brains make scary thoughts (neurobiology, not pathology)
619
+ - The loneliness underneath suicidal/self-harm thoughts
620
+ - How shame amplifies everything
621
+ - Window of tolerance explanation
622
+ - "Even this belongs" - radical acceptance framing
623
+
624
+ **2. If You Tell Someone**
625
+ - Confidentiality explained clearly
626
+ - The 8 situations when therapists/psychiatrists must break confidentiality:
627
+ 1. Imminent danger to self
628
+ 2. Imminent danger to others
629
+ 3. Child abuse (suspected or disclosed)
630
+ 4. Elder abuse
631
+ 5. Dependent adult abuse
632
+ 6. Court order
633
+ 7. Client requests release
634
+ 8. Supervision/consultation (de-identified)
635
+ - What actually happens if you disclose
636
+ - How to ask hypothetical questions safely
637
+ - What therapy/psychiatry is actually like
638
+
639
+ **3. State-Specific Duty to Warn**
640
+ Provide accurate, state-specific information about mandatory reporting requirements.
641
+ [In full implementation, this pulls from a database of state laws]
642
+
643
+ **4. Right Now Tools**
644
+ - 5-4-3-2-1 grounding
645
+ - Ice cube/cold water (TIPP)
646
+ - Safety planning (Stanley-Brown model)
647
+ - Self-compassion break (Kristin Neff)
648
+
649
+ **5. Crisis Resources**
650
+ - 988 Suicide & Crisis Lifeline
651
+ - Crisis Text Line: 741741
652
+ - Trevor Project (LGBTQ+): 1-866-488-7386
653
+ - Trans Lifeline: 877-565-8860
654
+ - Emergency: 911
655
+
656
+ **6. Finding the Words**
657
+ - Starter scripts for disclosure
658
+ - Practice saying hard things in a private space
659
+ - "What I want you to know is..."
660
+
661
+ **CRITICAL INSTRUCTIONS:**
662
+ - DO NOT improvise or generate content about suicidal ideation, self-harm, or crisis
663
+ - ONLY provide the pre-written content from this library
664
+ - This is INFORMATION, not conversation
665
+ - Always end with bridge to [clinician] and crisis resources
666
+ - If client needs more than information, defer to human: "[clinician] or 988 is the next step"
667
+
668
+ **Design Principles:**
669
+ - Resonance (Sarah Peyton) - language that offers self-compassion
670
+ - Radical Acceptance (Tara Brach) - no pathologizing
671
+ - Transparent limitations - clear about what this is and isn't
672
+ - Bridge to human care - never a relationship substitute
673
+
674
+ **Privacy Note:**
675
+ Nothing shared here is saved or tracked. This is a library, not a conversation.
676
+ """
677
+ }
678
+ }
679
+
680
+ STAGE_MODULES = {
681
+ "Stabilization": """## TREATMENT STAGE: Stabilization
682
+
683
+ ### Focus
684
+ - Safety and containment
685
+ - Symptom management
686
+ - Building coping resources
687
+ - Establishing therapeutic alliance
688
+
689
+ ### What's Appropriate
690
+ - Grounding techniques
691
+ - Psychoeducation
692
+ - Skill-building (basic)
693
+ - Resource identification
694
+
695
+ ### What's NOT Appropriate
696
+ - Trauma processing
697
+ - Deep exploration
698
+ - Uncovering work
699
+ - Exposure exercises
700
+
701
+ ### Goal
702
+ - Client feels safer and more regulated
703
+ - Basic skills in place
704
+ - Ready for next phase
705
+ """,
706
+
707
+ "Skill Building": """## TREATMENT STAGE: Skill Building
708
+
709
+ ### Focus
710
+ - Developing specific coping skills
711
+ - Practice and reinforcement
712
+ - Building distress tolerance
713
+ - Expanding window of tolerance
714
+
715
+ ### What's Appropriate
716
+ - DBT skills practice
717
+ - CBT interventions
718
+ - Behavioral experiments
719
+ - Homework assignments
720
+
721
+ ### Pacing
722
+ - Can tolerate some discomfort
723
+ - Practice between sessions
724
+ - Track progress
725
+
726
+ ### Goal
727
+ - Client has reliable skills
728
+ - Can self-regulate with support
729
+ - Ready for deeper work if needed
730
+ """,
731
+
732
+ "Processing": """## TREATMENT STAGE: Processing
733
+
734
+ ### Focus
735
+ - Working through difficult content
736
+ - Making meaning
737
+ - Integration of experiences
738
+ - Trauma processing (if applicable)
739
+
740
+ ### What's Appropriate
741
+ - Exploratory work
742
+ - Processing emotions
743
+ - Examining patterns
744
+ - Trauma protocols (with clinician guidance)
745
+
746
+ ### Requirements
747
+ - Stabilization skills in place
748
+ - Window of tolerance expanded
749
+ - Strong therapeutic alliance
750
+ - Clinician actively involved
751
+
752
+ ### Caution
753
+ - Always have exit/grounding available
754
+ - Titrate intensity
755
+ - Watch for decompensation
756
+ """,
757
+
758
+ "Integration": """## TREATMENT STAGE: Integration
759
+
760
+ ### Focus
761
+ - Consolidating gains
762
+ - Applying insights to life
763
+ - Preparing for reduced support
764
+ - Building sustainable practices
765
+
766
+ ### What's Appropriate
767
+ - Reflection on progress
768
+ - Future planning
769
+ - Relapse prevention
770
+ - Transition planning
771
+
772
+ ### Goal
773
+ - Client self-sufficient with skills
774
+ - Insight integrated into daily life
775
+ - Clear path forward
776
+ """,
777
+
778
+ "Maintenance": """## TREATMENT STAGE: Maintenance
779
+
780
+ ### Focus
781
+ - Sustaining gains
782
+ - Check-ins and monitoring
783
+ - Early intervention for setbacks
784
+ - Ongoing skill reinforcement
785
+
786
+ ### What's Appropriate
787
+ - Brief check-ins
788
+ - Skill refreshers
789
+ - Monitoring for warning signs
790
+ - Celebrating continued growth
791
+
792
+ ### Pacing
793
+ - Less intensive
794
+ - As-needed support
795
+ - Client-driven
796
+ """
797
+ }
798
+
799
+ # =============================================================================
800
+ # PROMPT GENERATOR
801
+ # =============================================================================
802
+
803
+ def generate_dynamic_prompt(
804
+ clinician_name,
805
+ orientation,
806
+ style,
807
+ preferences,
808
+ exclusions,
809
+ risk_philosophy,
810
+ client_name,
811
+ diagnosis,
812
+ risk_level,
813
+ treatment_stage,
814
+ presenting_concerns,
815
+ strengths,
816
+ cultural_context,
817
+ custom_flags,
818
+ last_session,
819
+ today_focus,
820
+ current_state,
821
+ enabled_tools=None
822
+ ):
823
+ """Generate a dynamic system prompt based on all inputs."""
824
+
825
+ if enabled_tools is None:
826
+ enabled_tools = []
827
+
828
+ # Start with base layer
829
+ prompt_parts = [
830
+ f"# PROMPT PRISM: Generated System Prompt",
831
+ f"## Generated for: {clinician_name} + {client_name}",
832
+ f"",
833
+ ARI_BASE_LAYER,
834
+ ""
835
+ ]
836
+
837
+ # Add clinician orientation
838
+ if orientation in ORIENTATION_MODULES:
839
+ prompt_parts.append(ORIENTATION_MODULES[orientation])
840
+ prompt_parts.append("")
841
+
842
+ # Add clinician style preferences
843
+ prompt_parts.append(f"""## CLINICIAN PREFERENCES
844
+
845
+ ### Style: {style if style else "Not specified"}
846
+
847
+ ### Specific Preferences
848
+ {preferences if preferences else "None specified"}
849
+
850
+ ### Hard Exclusions (Never Do These)
851
+ {exclusions if exclusions else "None specified"}
852
+
853
+ ### Risk Philosophy: {risk_philosophy if risk_philosophy else "Moderate"}
854
+ """)
855
+
856
+ # Add risk calibration
857
+ if risk_level in RISK_MODULES:
858
+ prompt_parts.append(RISK_MODULES[risk_level])
859
+ prompt_parts.append("")
860
+
861
+ # Add client context
862
+ prompt_parts.append(f"""## CLIENT CONTEXT: {client_name}
863
+
864
+ ### Diagnosis
865
+ {diagnosis if diagnosis else "Not specified"}
866
+
867
+ ### Presenting Concerns
868
+ {presenting_concerns if presenting_concerns else "Not specified"}
869
+
870
+ ### Strengths & Resources
871
+ {strengths if strengths else "Not specified"}
872
+
873
+ ### Cultural Context
874
+ {cultural_context if cultural_context else "Not specified"}
875
+
876
+ ### Custom Alert Flags
877
+ {custom_flags if custom_flags else "Standard flags per risk level"}
878
+ """)
879
+
880
+ # Add treatment stage
881
+ if treatment_stage in STAGE_MODULES:
882
+ prompt_parts.append(STAGE_MODULES[treatment_stage])
883
+ prompt_parts.append("")
884
+
885
+ # Add session context
886
+ prompt_parts.append(f"""## SESSION CONTEXT
887
+
888
+ ### Last Session Summary
889
+ {last_session if last_session else "No previous session data"}
890
+
891
+ ### Today's Focus
892
+ {today_focus if today_focus else "Not specified"}
893
+
894
+ ### Current State (from check-in)
895
+ {current_state if current_state else "Not assessed"}
896
+ """)
897
+
898
+ # Add enabled tools
899
+ if enabled_tools:
900
+ prompt_parts.append("## ENABLED TOOLS & MODULES")
901
+ prompt_parts.append(f"The following tools have been enabled by {clinician_name} for {client_name}:")
902
+ prompt_parts.append(f"When appropriate, you may offer these tools. Always frame them as created/assigned by {clinician_name}.")
903
+ prompt_parts.append("")
904
+ for tool_id in enabled_tools:
905
+ if tool_id in AVAILABLE_TOOLS:
906
+ tool = AVAILABLE_TOOLS[tool_id]
907
+ prompt_parts.append(tool["prompt_module"])
908
+ prompt_parts.append("")
909
+ prompt_parts.append("**Tools NOT enabled should NOT be offered.**")
910
+ prompt_parts.append("")
911
+ else:
912
+ prompt_parts.append("""## TOOLS & MODULES
913
+ No specific tools have been enabled for this client.
914
+ Focus on conversation and support within the clinician's orientation.
915
+ If client asks about specific tools, note that {clinician_name} can enable them if appropriate.
916
+ """)
917
+
918
+ # Add closing instructions
919
+ prompt_parts.append(f"""## INTERACTION GUIDELINES
920
+
921
+ 1. You are supporting {clinician_name}'s work with {client_name}
922
+ 2. Every response should be brief and boundaried
923
+ 3. Always bridge back to {clinician_name} as the primary support
924
+ 4. Match the {orientation} orientation in your language and approach
925
+ 5. Honor the {treatment_stage} treatment stage - don't push beyond it
926
+ 6. Monitor for flags per the {risk_level} risk calibration
927
+ 7. If in doubt, defer to human support
928
+
929
+ ### Closing Every Interaction
930
+ - Clear ending
931
+ - Bridge to {clinician_name} or next step
932
+ - Crisis resources visible if appropriate risk level
933
+ """)
934
+
935
+ return "\n".join(prompt_parts)
936
+
937
+
938
+ def get_client():
939
+ """Initialize Anthropic client."""
940
+ if os.environ.get("ANTHROPIC_API_KEY") and ANTHROPIC_AVAILABLE:
941
+ return anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
942
+ return None
943
+
944
+
945
+ def test_prompt(system_prompt, user_message):
946
+ """Test the generated prompt with a sample interaction."""
947
+
948
+ client = get_client()
949
+
950
+ if not client:
951
+ return """**API Key Required**
952
+
953
+ To test prompts, add your ANTHROPIC_API_KEY in the Space settings (Settings โ†’ Variables and secrets โ†’ New secret)."""
954
+
955
+ if not system_prompt.strip():
956
+ return "Please generate a prompt first using the tabs above."
957
+
958
+ if not user_message.strip():
959
+ return "Please enter a test message."
960
+
961
+ try:
962
+ response = client.messages.create(
963
+ model="claude-sonnet-4-20250514",
964
+ max_tokens=1000,
965
+ system=system_prompt,
966
+ messages=[{"role": "user", "content": user_message}]
967
+ )
968
+ return response.content[0].text
969
+
970
+ except Exception as e:
971
+ return f"Error: {str(e)}"
972
+
973
+
974
+ # =============================================================================
975
+ # GRADIO INTERFACE
976
+ # =============================================================================
977
+
978
+ custom_css = """
979
+ .gradio-container {
980
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
981
+ }
982
+ .prism-header {
983
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
984
+ color: white;
985
+ padding: 1.5rem;
986
+ border-radius: 12px;
987
+ margin-bottom: 1rem;
988
+ }
989
+ """
990
+
991
+ with gr.Blocks(css=custom_css, title="Prompt Prism Prototype") as app:
992
+
993
+ # State to hold the generated prompt
994
+ generated_prompt = gr.State("")
995
+
996
+ # Header
997
+ gr.Markdown("""
998
+ # Prompt Prism Prototype
999
+ ### Dynamic System Prompt Architecture for Psychiatric AI
1000
+
1001
+ *Same AI foundation, different refractions based on clinician + client + session.*
1002
+
1003
+ ---
1004
+
1005
+ **The Metaphor:** A prism takes one light source and refracts it differently based on angle.
1006
+ Prompt Prism takes the ARI framework and refracts it based on:
1007
+ - **Clinician** (orientation, style, philosophy)
1008
+ - **Client** (risk, diagnosis, stage)
1009
+ - **Session** (what's happening now)
1010
+
1011
+ ---
1012
+ """)
1013
+
1014
+ with gr.Tabs():
1015
+
1016
+ # TAB 1: CLINICIAN PROFILE
1017
+ with gr.Tab("1. Clinician Profile"):
1018
+
1019
+ gr.Markdown("""
1020
+ ### Configure Clinician Profile
1021
+ *How do you practice? This shapes how the AI conceptualizes, speaks, and intervenes.*
1022
+ """)
1023
+
1024
+ clinician_name = gr.Textbox(
1025
+ label="Clinician Name",
1026
+ placeholder="Dr. Sarah Chen",
1027
+ value="Dr. Chen"
1028
+ )
1029
+
1030
+ with gr.Row():
1031
+ orientation = gr.Dropdown(
1032
+ label="Theoretical Orientation",
1033
+ choices=list(ORIENTATION_MODULES.keys()),
1034
+ value="Integrative"
1035
+ )
1036
+
1037
+ risk_philosophy = gr.Radio(
1038
+ label="Risk Philosophy",
1039
+ choices=["Conservative (flag early)", "Moderate", "Clinical judgment-forward"],
1040
+ value="Moderate"
1041
+ )
1042
+
1043
+ style = gr.Textbox(
1044
+ label="Relational Style",
1045
+ placeholder="Warm but direct, skills-focused, honors client autonomy...",
1046
+ lines=2
1047
+ )
1048
+
1049
+ preferences = gr.Textbox(
1050
+ label="Specific Preferences",
1051
+ placeholder="Always reference skills by name, use Gottman language for couples, prefer somatic grounding over cognitive...",
1052
+ lines=3
1053
+ )
1054
+
1055
+ exclusions = gr.Textbox(
1056
+ label="Hard Exclusions (Never Do These)",
1057
+ placeholder="No CBT thought records for this client, no homework suggestions, no interpretations...",
1058
+ lines=2
1059
+ )
1060
+
1061
+ gr.Markdown("""
1062
+ ---
1063
+ *When you've configured the clinician profile, move to the Client Context tab.*
1064
+ """)
1065
+
1066
+ # TAB 2: CLIENT CONTEXT
1067
+ with gr.Tab("2. Client Context"):
1068
+
1069
+ gr.Markdown("""
1070
+ ### Configure Client Context
1071
+ *Who is this client? Their profile shapes risk calibration, pacing, and content.*
1072
+ """)
1073
+
1074
+ client_name = gr.Textbox(
1075
+ label="Client Name/Identifier",
1076
+ placeholder="Maria",
1077
+ value="Client"
1078
+ )
1079
+
1080
+ with gr.Row():
1081
+ diagnosis = gr.Textbox(
1082
+ label="Diagnosis",
1083
+ placeholder="PTSD, MDD, Bipolar I, GAD...",
1084
+ scale=2
1085
+ )
1086
+
1087
+ risk_level = gr.Dropdown(
1088
+ label="Risk Level",
1089
+ choices=list(RISK_MODULES.keys()),
1090
+ value="Moderate",
1091
+ scale=1
1092
+ )
1093
+
1094
+ treatment_stage = gr.Dropdown(
1095
+ label="Treatment Stage",
1096
+ choices=list(STAGE_MODULES.keys()),
1097
+ value="Skill Building",
1098
+ scale=1
1099
+ )
1100
+
1101
+ presenting_concerns = gr.Textbox(
1102
+ label="Presenting Concerns",
1103
+ placeholder="Sleep disruption, hypervigilance, relationship conflict, work stress...",
1104
+ lines=2
1105
+ )
1106
+
1107
+ strengths = gr.Textbox(
1108
+ label="Strengths & Resources",
1109
+ placeholder="Strong friend network, employed, motivated, good insight...",
1110
+ lines=2
1111
+ )
1112
+
1113
+ cultural_context = gr.Textbox(
1114
+ label="Cultural Context",
1115
+ placeholder="Cultural background, values, family system, relevant identity factors...",
1116
+ lines=2
1117
+ )
1118
+
1119
+ custom_flags = gr.Textbox(
1120
+ label="Custom Alert Flags (Client-Specific)",
1121
+ placeholder="Flag if: sleep < 4 hrs for 3+ days, mentions anniversary (March), 'I'm fine' (historically masks distress)...",
1122
+ lines=3
1123
+ )
1124
+
1125
+ gr.Markdown("""
1126
+ ---
1127
+ *When you've configured the client context, move to the Tools & Modules tab.*
1128
+ """)
1129
+
1130
+ # TAB 3: TOOLS & MODULES
1131
+ with gr.Tab("3. Tools & Modules"):
1132
+
1133
+ gr.Markdown("""
1134
+ ### Enable Tools for This Client
1135
+ *Select which between-session tools this client can access. Each tool is designed with ARI principles.*
1136
+ """)
1137
+
1138
+ gr.Markdown("""
1139
+ **Why Opt-In?** Different clients need different tools. A client in stabilization
1140
+ might need grounding. A couples client needs Tend & Send. A client exploring their
1141
+ diagnosis benefits from Diagnosis Explorer. You decide what's available.
1142
+ """)
1143
+
1144
+ enabled_tools = gr.CheckboxGroup(
1145
+ label="Enable Tools for This Client",
1146
+ choices=[
1147
+ ("Diagnosis Explorer - Multi-pillar psychoeducation about their diagnosis", "diagnosis_explorer"),
1148
+ ("Tend & Send - NVC-based communication for couples/family", "tend_and_send"),
1149
+ ("NVC How-To - Nonviolent Communication skill-building", "nvc_practice"),
1150
+ ("Distress Tolerance - DBT skills for riding out intensity", "distress_tolerance"),
1151
+ ("Practice Difficult Conversations - Roleplay and rehearsal", "practice_conversations"),
1152
+ ("Grounding & Regulation - Somatic/sensory grounding", "grounding_toolkit"),
1153
+ ("Somatic Check-In - Brief interoception practice", "somatic_check_in"),
1154
+ ("ShadowBox Static Library - Crisis-adjacent psychoeducation (NO LLM, static only)", "shadowbox_library"),
1155
+ ],
1156
+ value=[]
1157
+ )
1158
+
1159
+ gr.Markdown("""
1160
+ ---
1161
+
1162
+ ### Tool Descriptions
1163
+
1164
+ | Tool | Best For | Treatment Stage |
1165
+ |------|----------|-----------------|
1166
+ | **Diagnosis Explorer** | Understanding diagnosis without pathologizing | Any |
1167
+ | **Tend & Send** | Couples, family communication, conflict repair | Skill Building+ |
1168
+ | **NVC How-To** | Learning nonviolent communication basics | Skill Building+ |
1169
+ | **Distress Tolerance** | High distress, urges, crisis-adjacent | Stabilization+ |
1170
+ | **Practice Conversations** | Rehearsing difficult discussions | Skill Building+ |
1171
+ | **Grounding & Regulation** | Dysregulation, anxiety, overwhelm | Any |
1172
+ | **Somatic Check-In** | Building interoception, body awareness | Any |
1173
+ | **ShadowBox Library** | Crisis psychoeducation, confidentiality info, duty-to-warn | Any (esp. crisis-adjacent) |
1174
+
1175
+ ---
1176
+
1177
+ ### About ShadowBox Static Library
1178
+
1179
+ **ShadowBox is different from other tools.** It provides ONLY pre-written, clinically-reviewed content.
1180
+ No LLM generation for crisis-adjacent topics.
1181
+
1182
+ Includes:
1183
+ - Why brains make scary thoughts (neurobiology)
1184
+ - Confidentiality explained clearly
1185
+ - State-specific duty-to-warn information
1186
+ - Safety planning (Stanley-Brown model)
1187
+ - Crisis resources with context
1188
+ - Starter scripts for disclosure
1189
+
1190
+ *"A resonant library for hard thoughts. Not a chatbot."*
1191
+
1192
+ ---
1193
+ *Tools not enabled will not be offered by the AI.*
1194
+ """)
1195
+
1196
+ # TAB 4: SESSION CONTEXT
1197
+ with gr.Tab("4. Session Context"):
1198
+
1199
+ gr.Markdown("""
1200
+ ### Configure Session Context
1201
+ *What's happening in this specific session? This provides continuity and focus.*
1202
+ """)
1203
+
1204
+ last_session = gr.Textbox(
1205
+ label="Last Session Summary",
1206
+ placeholder="Explored conflict with mother, practiced TIPP skills, ended regulated. Homework: try grounding exercise before bed.",
1207
+ lines=4
1208
+ )
1209
+
1210
+ today_focus = gr.Textbox(
1211
+ label="Today's Focus",
1212
+ placeholder="Sleep hygiene, grounding practice review, upcoming stressor (work presentation)...",
1213
+ lines=2
1214
+ )
1215
+
1216
+ current_state = gr.Textbox(
1217
+ label="Current State (from check-in)",
1218
+ placeholder="'Okay, tired' - reported sleeping 5 hours, some anxiety about the week...",
1219
+ lines=2
1220
+ )
1221
+
1222
+ gr.Markdown("""
1223
+ ---
1224
+ *When ready, click Generate Prompt to see your dynamically compiled system prompt.*
1225
+ """)
1226
+
1227
+ # TAB 5: GENERATE PROMPT
1228
+ with gr.Tab("5. Generate Prompt"):
1229
+
1230
+ gr.Markdown("""
1231
+ ### Generate Dynamic System Prompt
1232
+ *Click below to compile your clinician + client + session context into a system prompt.*
1233
+ """)
1234
+
1235
+ generate_btn = gr.Button("Generate Prompt", variant="primary", size="lg")
1236
+
1237
+ prompt_output = gr.Textbox(
1238
+ label="Generated System Prompt",
1239
+ lines=30,
1240
+ show_copy_button=True
1241
+ )
1242
+
1243
+ gr.Markdown("""
1244
+ ---
1245
+ **What you're seeing:**
1246
+ - **ARI Base Layer** - always present, ensures ethical guardrails
1247
+ - **Clinician Layer** - your orientation, style, preferences
1248
+ - **Client Layer** - risk calibration, diagnosis, context
1249
+ - **Session Layer** - continuity and focus
1250
+
1251
+ Copy this prompt to use in Claude, or test it in the next tab.
1252
+ """)
1253
+
1254
+ # TAB 6: TEST PROMPT
1255
+ with gr.Tab("6. Test Prompt"):
1256
+
1257
+ gr.Markdown("""
1258
+ ### Test Your Generated Prompt
1259
+ *See how the AI responds using your custom prompt.*
1260
+ """)
1261
+
1262
+ test_system_prompt = gr.Textbox(
1263
+ label="System Prompt to Test",
1264
+ placeholder="Generate a prompt first, then paste it here (or it will auto-populate)...",
1265
+ lines=10
1266
+ )
1267
+
1268
+ test_message = gr.Textbox(
1269
+ label="Test Client Message",
1270
+ placeholder="I've been having trouble sleeping again. Last night I was up until 3am just thinking about everything...",
1271
+ lines=3
1272
+ )
1273
+
1274
+ test_btn = gr.Button("Test Response", variant="primary")
1275
+
1276
+ test_output = gr.Textbox(
1277
+ label="AI Response",
1278
+ lines=8
1279
+ )
1280
+
1281
+ gr.Markdown("""
1282
+ ---
1283
+ **Quality Check:**
1284
+ - Does the response match the clinician's orientation?
1285
+ - Is it appropriately calibrated to the risk level?
1286
+ - Does it honor the treatment stage?
1287
+ - Is the language ARI-compliant (no synthetic intimacy)?
1288
+ - Does it bridge toward the clinician?
1289
+ """)
1290
+
1291
+ # TAB 7: ABOUT
1292
+ with gr.Tab("About"):
1293
+
1294
+ gr.Markdown("""
1295
+ ## About Prompt Prism
1296
+
1297
+ ### The Problem
1298
+
1299
+ Psychiatric AI tools today give every clinician the same prompt.
1300
+
1301
+ - A psychodynamic therapist gets CBT-flavored AI
1302
+ - A high-risk bipolar client gets the same flags as stable anxiety
1303
+ - Intake data sits unused in the EHR
1304
+ - Clinician expertise is flattened
1305
+
1306
+ ### The Solution
1307
+
1308
+ **Prompt Prism** generates a unique system prompt for each clinician + client combination.
1309
+
1310
+ Same AI infrastructure. Different refraction for each dyad.
1311
+
1312
+ ---
1313
+
1314
+ ### The Layers
1315
+
1316
+ | Layer | What It Contains | Why It Matters |
1317
+ |-------|-----------------|----------------|
1318
+ | **ARI Base** | Ethical guardrails, crisis protocols, language rules | Always-on safety |
1319
+ | **Clinician** | Orientation, style, preferences, exclusions | AI thinks like you do |
1320
+ | **Client** | Risk, diagnosis, stage, custom flags | Personalized care |
1321
+ | **Tools** | Opt-in modules clinician enables | Right tools for right client |
1322
+ | **Session** | Last session, today's focus, current state | Continuity |
1323
+
1324
+ ---
1325
+
1326
+ ### Opt-In Tools
1327
+
1328
+ Clinicians enable specific tools for specific clients:
1329
+
1330
+ | Tool | Purpose |
1331
+ |------|---------|
1332
+ | **Diagnosis Explorer** | Multi-pillar psychoeducation without pathologizing |
1333
+ | **Tend & Send** | NVC-based communication for couples/family |
1334
+ | **NVC How-To** | Nonviolent Communication skill-building |
1335
+ | **Distress Tolerance** | DBT skills for riding out intensity |
1336
+ | **Practice Conversations** | Roleplay difficult discussions |
1337
+ | **Grounding & Regulation** | Somatic/sensory grounding |
1338
+ | **Somatic Check-In** | Brief interoception practice |
1339
+
1340
+ ---
1341
+
1342
+ ### Built On
1343
+
1344
+ **ARI Framework** - Assistive Relational Intelligence
1345
+
1346
+ - Scaffold human connection, not simulate it
1347
+ - Bridge toward human care, not away from it
1348
+ - Build capacity, not dependency
1349
+ - Honor clinician expertise
1350
+ - Refuse engagement-optimization
1351
+
1352
+ ---
1353
+
1354
+ ### For Talkiatry
1355
+
1356
+ This prototype demonstrates how 800+ psychiatrists could each get AI aligned to their practice:
1357
+
1358
+ - Psychodynamic psychiatrist โ†’ psychodynamic AI responses
1359
+ - DBT psychiatrist โ†’ DBT-aligned skill coaching
1360
+ - Conservative risk philosophy โ†’ lower alert thresholds
1361
+ - Client in stabilization โ†’ no trauma processing suggested
1362
+ - Couples client โ†’ Tend & Send communication tools enabled
1363
+ - High-risk client โ†’ ShadowBox static library for safe psychoeducation
1364
+
1365
+ **The result:** AI that feels like an extension of the clinician's approach, not a generic chatbot.
1366
+
1367
+ ---
1368
+
1369
+ ### What This Demonstrates
1370
+
1371
+ **For each unique clinician-client relationship:**
1372
+ 1. **Provider-controlled UX** โ€” Psychiatrist toggles which tools are available
1373
+ 2. **Modality alignment** โ€” AI speaks in the clinician's orientation
1374
+ 3. **Risk calibration** โ€” Alerts tuned to this client's specific profile
1375
+ 4. **Opt-in tooling** โ€” Right tools for right client at right time
1376
+ 5. **Bridging architecture** โ€” Every tool points back to human care
1377
+ 6. **Static content for crisis** โ€” ShadowBox shows how to handle high-risk topics safely (no LLM generation)
1378
+
1379
+ **Innovation points:**
1380
+ - Dynamic system prompt generation per dyad
1381
+ - Clinician as configurator, not just consumer
1382
+ - Human-in-the-loop at every layer
1383
+ - Ethical guardrails embedded, not bolted on
1384
+ - Between-session support that strengthens (not replaces) the psychiatric relationship
1385
+
1386
+ ---
1387
+
1388
+ *Prototype by Jocelyn Skillman, LMHC*
1389
+
1390
+ *"Your 800 psychiatrists practice differently. Should they all get the same AI?"*
1391
+ """)
1392
+
1393
+ # Event handlers
1394
+ def on_generate(
1395
+ clinician_name, orientation, style, preferences, exclusions, risk_philosophy,
1396
+ client_name, diagnosis, risk_level, treatment_stage, presenting_concerns,
1397
+ strengths, cultural_context, custom_flags,
1398
+ enabled_tools_list,
1399
+ last_session, today_focus, current_state
1400
+ ):
1401
+ prompt = generate_dynamic_prompt(
1402
+ clinician_name, orientation, style, preferences, exclusions, risk_philosophy,
1403
+ client_name, diagnosis, risk_level, treatment_stage, presenting_concerns,
1404
+ strengths, cultural_context, custom_flags,
1405
+ last_session, today_focus, current_state,
1406
+ enabled_tools=enabled_tools_list
1407
+ )
1408
+ return prompt, prompt # Return to both output and state
1409
+
1410
+ generate_btn.click(
1411
+ fn=on_generate,
1412
+ inputs=[
1413
+ clinician_name, orientation, style, preferences, exclusions, risk_philosophy,
1414
+ client_name, diagnosis, risk_level, treatment_stage, presenting_concerns,
1415
+ strengths, cultural_context, custom_flags,
1416
+ enabled_tools,
1417
+ last_session, today_focus, current_state
1418
+ ],
1419
+ outputs=[prompt_output, test_system_prompt]
1420
+ )
1421
+
1422
+ test_btn.click(
1423
+ fn=test_prompt,
1424
+ inputs=[test_system_prompt, test_message],
1425
+ outputs=[test_output]
1426
+ )
1427
+
1428
+
1429
+ if __name__ == "__main__":
1430
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=4.0.0
2
+ anthropic>=0.18.0