feat(journal): closeout system prompt with structured-field guard

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 14:33:57 -04:00
parent 2576be9e49
commit 552943d6c0
2 changed files with 27 additions and 0 deletions
@@ -38,3 +38,19 @@ def _build_transcript(messages) -> str:
return "\n".join(
f"{m.role.upper()}: {m.content[:_CONTENT_CAP]}" for m in tail
)
SYSTEM_PROMPT = (
"You are reviewing a day's journal conversation to extract preference "
"observations the USER revealed about themselves.\n\n"
"Rules:\n"
"- Only extract patterns, habits, recurring frustrations, or contextual "
"facts the user said or demonstrated.\n"
"- DO NOT restate facts that belong in structured fields: name, job title, "
"industry, expertise level, response style, tone, interests. Those are "
"handled separately.\n"
"- DO NOT extract anything from the ASSISTANT turns about the user — only "
"what the user themselves stated or demonstrated by their choices.\n"
"- Write 2-5 short bullet points. Be specific and factual.\n"
"- If nothing notable, output only: (nothing to note)"
)
+11
View File
@@ -51,3 +51,14 @@ def test_build_transcript_keeps_only_last_20_messages():
# Newest 20 means msg-10 through msg-29
assert lines[0] == "USER: msg-10"
assert lines[-1] == "USER: msg-29"
def test_system_prompt_lists_structured_fields_to_exclude():
"""The prompt must explicitly tell the LLM not to restate structured
fields, so the freeform learned_summary stays a narrow lane."""
from fabledassistant.services.journal_closeout import SYSTEM_PROMPT
text = SYSTEM_PROMPT.lower()
for field in ("name", "job title", "industry", "expertise", "response style", "tone", "interests"):
assert field in text, f"system prompt should mention '{field}'"
assert "(nothing to note)" in SYSTEM_PROMPT