StemGraph_AI / guard.py
Subh775's picture
redic-cache;styles;ui;auth;etc..
767deae
Raw
History Blame Contribute Delete
606 Bytes
"""
Input guard — lightweight pre-check before LLM call.
No explicit word lists. Abuse handling is delegated to the system prompt.
"""
def check_input(message: str) -> tuple[bool, str | None]:
"""
Basic pre-checks that don't need an LLM call.
Returns (True, None) if OK, or (False, rejection_message) if blocked.
Abuse/profanity is handled by the system prompt, not here.
"""
text = message.strip()
if not text:
return False, "Empty message."
if len(text) > 5000:
return False, "Message too long. Keep it under 5000 characters."
return True, None