fix: tighten 20q answer cap to prevent answer leakage
Lint / Shell (shellcheck) (push) Successful in 9s
Lint / JS (eslint) (push) Successful in 8s
Lint / Python (ruff) (push) Successful in 4s
Lint / Python deps (pip-audit) (push) Successful in 42s
Lint / Secret scan (gitleaks) (push) Successful in 5s

Reduce word cap from 12 to 6 and add explicit instructions not to use
proper nouns, brand names, or place names in answers. Fixes the case
where the model blurted 'The Grand Canyon State (Arizona)' in response
to a geography question.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 20:08:03 -04:00
parent ee38b1e76a
commit 75f9c7bdb9
+6 -5
View File
@@ -2807,9 +2807,10 @@ async def _answer_20q(thing: str, category: str, question: str) -> str:
system_msg = (
f'You are playing 20 questions. You are thinking of: "{thing}" ({category}). '
"Answer the player's question honestly and helpfully. "
"For yes/no questions: answer Yes, No, Sometimes, or Partly. "
"For open questions (color, size, shape, etc.): give a brief, accurate answer in 1-8 words. "
"CRITICAL: Do NOT say the name of the thing. Do NOT give it away. Keep answers short."
"For yes/no questions: answer Yes, No, Sometimes, or Partly — nothing else. "
"For open questions (color, size, etc.): give a vague but accurate 1-5 word answer. "
"CRITICAL: Never name the thing directly or say anything that uniquely identifies it. "
"Never mention proper nouns, brand names, or place names in your answer."
)
try:
timeout = aiohttp.ClientTimeout(total=20)
@@ -2822,9 +2823,9 @@ async def _answer_20q(thing: str, category: str, question: str) -> str:
) as response:
data = await response.json()
raw = data.get("message", {}).get("content", "").strip()
# Cap at 12 words to prevent the model rambling and leaking the answer
# Hard cap at 6 words — enough for a real answer, not enough to name-drop
words = raw.split()
return " ".join(words[:12]) if words else "..."
return " ".join(words[:6]) if words else "..."
except Exception as e:
logger.error("20q answer error: %s", e, exc_info=True)
return "..."