feat(07-01): DB migration 009, ORM updates, and LANGUAGE_INSTRUCTION in system prompts

- Migration 009: adds language col (VARCHAR 10, NOT NULL, default 'en') to portal_users
- Migration 009: adds translations col (JSONB, NOT NULL, default '{}') to agent_templates
- Migration 009: backfills es+pt translations for all 7 seed templates
- PortalUser ORM: language mapped column added
- AgentTemplate ORM: translations mapped column added
- system_prompt_builder.py: LANGUAGE_INSTRUCTION constant + appended before AI_TRANSPARENCY_CLAUSE
- system-prompt-builder.ts: LANGUAGE_INSTRUCTION constant + appended before AI transparency clause
- tests: TestLanguageInstruction class with 3 tests (all pass, 20 total)
This commit is contained in:
2026-03-25 16:22:53 -06:00
parent 5cd9305d27
commit 7a3a4f0fdd
6 changed files with 394 additions and 1 deletions

View File

@@ -166,3 +166,43 @@ class TestBuildSystemPromptAIClauseAlwaysPresent:
def test_ai_clause_present_with_persona_only(self) -> None:
prompt = build_system_prompt(name="Sam", role="Analyst", persona="Detail-oriented")
assert AI_TRANSPARENCY_CLAUSE in prompt
class TestLanguageInstruction:
"""LANGUAGE_INSTRUCTION must be present in all system prompts before AI transparency clause."""
LANGUAGE_INSTRUCTION = (
"Detect the language of each user message and respond in that same language. "
"You support English, Spanish, and Portuguese."
)
def test_language_instruction_present_in_default_prompt(self) -> None:
"""build_system_prompt with name+role includes LANGUAGE_INSTRUCTION."""
prompt = build_system_prompt(name="Mara", role="Support Rep")
assert self.LANGUAGE_INSTRUCTION in prompt
def test_language_instruction_present_with_full_args(self) -> None:
"""build_system_prompt with all args includes LANGUAGE_INSTRUCTION."""
prompt = build_system_prompt(
name="Mara",
role="Support Rep",
persona="Helpful and professional",
tool_assignments=["knowledge_base_search"],
escalation_rules=[{"condition": "billing_dispute", "action": "handoff_human"}],
)
assert self.LANGUAGE_INSTRUCTION in prompt
def test_language_instruction_before_transparency_clause(self) -> None:
"""LANGUAGE_INSTRUCTION appears before AI_TRANSPARENCY_CLAUSE in the prompt."""
prompt = build_system_prompt(
name="Mara",
role="Support Rep",
persona="Helpful",
tool_assignments=["kb_search"],
escalation_rules=[{"condition": "x", "action": "handoff_human"}],
)
lang_pos = prompt.index(self.LANGUAGE_INSTRUCTION)
transparency_pos = prompt.index(AI_TRANSPARENCY_CLAUSE)
assert lang_pos < transparency_pos, (
"LANGUAGE_INSTRUCTION must appear before AI_TRANSPARENCY_CLAUSE"
)