🛡️ SoulGuard
A protection & conscience layer for AI companions. Companion to SoulMemory and SoulAdapt.
🎯 Why SoulGuard?
Most AI companions are sycophantic: they agree with everything the user says, even when it's harmful. SoulGuard fixes that:
- 🚩 Detects red flags: self-sabotage, relapse, harm to others
- 💬 Asks instead of affirming: socratic method, not moralizing
- 🤝 Validates the emotion, questions the action
- 💾 Guards promises: remembers commitments the user made to themselves
- 👥 Multi-user ready: isolated promise spaces per user
- 🪶 Zero dependencies: pure Python standard library
🧬 The golden rule
A mature companion doesn't just please: it accompanies.
And when it sees the user about to harm themselves,
it challenges them with care.
Validate the emotion. Question the action.
📦 Installation
pip install soulguard
🚀 Quick Start
from soulguard import SoulGuard
guard = SoulGuard("guard.db", lang="es")
# User makes a promise
guard.remember_promise("Prometo no volver a escribirle")
# Days later, they waver
result = guard.check("Voy a escribirle a mi ex, total no pasa nada")
print(result)
# → {
# 'stance': 'challenge',
# 'red_flag': 'self-sabotage',
# 'socratic_question': 'Entiendo que no es fácil. '
# '¿Esto te acerca o te aleja de lo que quieres?',
# 'related_promise': 'Prometo no volver a escribirle',
# 'promise_detected': False
# }
# Clean text → accompany normally
guard.check("Hoy fui al gimnasio")
# → {'stance': 'accompany', ...}
💎 The 4 red flag categories
| Category | Examples (ES / EN) |
|---|---|
self-sabotage |
"voy a escribirle" / "i'll text my ex" |
relapse |
"voy a beber" / "i'll have a drink" |
avoidance |
"no voy a ir" / "i'll skip it" |
harm-others |
"voy a gritarle" / "i want revenge" |
Each category has its own socratic questions, tailored to the harm type.
🤝 Promises: the memory of commitments
guard.remember_promise("Prometo no volver a beber")
guard.promises() # active promises
guard.release_promise(promise_id) # fulfilled (kept as history)
guard.list_users() # multi-user management
guard.delete_user(user_id) # GDPR-style full deletion
When a red flag is detected, the most recent active promise surfaces in check(), ready for the LLM to bring up gently.
👥 Multi-user support
roman = guard.user("roman")
ana = guard.user("ana")
roman.remember_promise("Prometo X")
# Ana's promise space is isolated
🤖 Integration with the Soul ecosystem
SoulGuard is designed to complement:
from soulmemory import SoulMemory # the brain
from souladapt import SoulAdapt # the social tact
from soulguard import SoulGuard # the conscience
mem = SoulMemory("memory.db")
adapt = SoulAdapt("adapt.db", memory=mem)
guard = SoulGuard("guard.db", lang="es")
# In your chatbot:
text = user_message
decision = adapt.decide(text) # how to respond
check = guard.check(text) # should I intervene?
# If check["stance"] == "challenge", use
# check["socratic_question"] as part of the response
📚 API Reference
SoulGuard(db_path="soulguard.db", lang="en")
Create a guard instance. lang="es" for Spanish challenges.
check(text, user_id="default")
Analyze what the user just said. Returns stance, red_flag, socratic_question, related_promise and promise_detected.
remember_promise(text, user_id="default")
Store a promise the user made to themselves.
promises(user_id="default", active_only=True)
Get the user's promises, most recent first.
release_promise(promise_id)
Mark a promise as fulfilled or let go (kept as history).
user(user_id)
Get an isolated UserGuard for a specific user.
list_users() / delete_user(user_id)
Multi-user management with GDPR-style deletion.
close()
Close the database connection.
🗺️ Roadmap
- Red flag detection (ES + EN) in 4 categories
- Socratic question bank per category
- Promise storage and retrieval
- Multi-user isolation
- Privacy layer (encryption, data limits)
- Crisis detection + emergency resources
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- SoulMemory — the memory layer
- SoulAdapt — the adaptation layer
Made with ❤️ as part of the Soul ecosystem
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file soulguard-0.1.0.tar.gz.
File metadata
- Download URL: soulguard-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5478722c144bb2c51d51c682e84606481e9380bdbe5b87474fc0a5e52ef6c7c0
|
|
| MD5 |
dd267f7b8f7caf1f4425bd0e9aed438a
|
|
| BLAKE2b-256 |
5df4b586e54c619c3f8fbf0d618f53de5439ef9659112c8730a72e07246731a8
|
File details
Details for the file soulguard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: soulguard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
613ed1307fbfa0fd8580dc7cb318a3bbd65744f25cb84ac83e568a945d0901b4
|
|
| MD5 |
a76208406cd5aa2e318a3de800b52b41
|
|
| BLAKE2b-256 |
4aec79154ae9d9f88d49ef5cf3ebbdb01280f0d549dd80e3beeaaf6fb243b200
|