From e2ecbc747dc4b17e005ec192587c7829fceb2c23 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Wed, 13 May 2026 13:34:29 -0600 Subject: [PATCH] fix(ai): forbid preamble in response-shortener output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tighten the system/user prompts so the shortener returns ONLY the rewritten message — no "Here's a version at N characters:" preamble, no quotes, no labels. Previously such preamble was being transmitted on-air and consumed the byte budget, causing the actual content to truncate. Co-Authored-By: Claude Opus 4.7 (1M context) --- orac/ai.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/orac/ai.py b/orac/ai.py index ee9459b..07a3762 100644 --- a/orac/ai.py +++ b/orac/ai.py @@ -50,10 +50,20 @@ def _shorten_with_claude(text: str, max_chars: int) -> str: model="claude-sonnet-4-6", max_tokens=256, timeout=CLAUDE_TIMEOUT_S, + system=( + "You rewrite a message to fit within a strict character budget. " + "Output ONLY the rewritten message — no preamble, no quotes, no " + "explanation, no commentary, no labels, no character count. " + "Preserve the original meaning, tone, and voice. Plain text only." + ), messages=[ { "role": "user", - "content": f"Shorten this to {max_chars} characters: {text}", + "content": ( + f"Rewrite the following message so it is at most " + f"{max_chars} characters. Reply with the rewritten " + f"message only.\n\n{text}" + ), } ], )