fix: tighten 20q answer cap to prevent answer leakage
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:
@@ -2807,9 +2807,10 @@ async def _answer_20q(thing: str, category: str, question: str) -> str:
|
|||||||
system_msg = (
|
system_msg = (
|
||||||
f'You are playing 20 questions. You are thinking of: "{thing}" ({category}). '
|
f'You are playing 20 questions. You are thinking of: "{thing}" ({category}). '
|
||||||
"Answer the player's question honestly and helpfully. "
|
"Answer the player's question honestly and helpfully. "
|
||||||
"For yes/no questions: answer Yes, No, Sometimes, or Partly. "
|
"For yes/no questions: answer Yes, No, Sometimes, or Partly — nothing else. "
|
||||||
"For open questions (color, size, shape, etc.): give a brief, accurate answer in 1-8 words. "
|
"For open questions (color, size, etc.): give a vague but accurate 1-5 word answer. "
|
||||||
"CRITICAL: Do NOT say the name of the thing. Do NOT give it away. Keep answers short."
|
"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:
|
try:
|
||||||
timeout = aiohttp.ClientTimeout(total=20)
|
timeout = aiohttp.ClientTimeout(total=20)
|
||||||
@@ -2822,9 +2823,9 @@ async def _answer_20q(thing: str, category: str, question: str) -> str:
|
|||||||
) as response:
|
) as response:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
raw = data.get("message", {}).get("content", "").strip()
|
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()
|
words = raw.split()
|
||||||
return " ".join(words[:12]) if words else "..."
|
return " ".join(words[:6]) if words else "..."
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("20q answer error: %s", e, exc_info=True)
|
logger.error("20q answer error: %s", e, exc_info=True)
|
||||||
return "..."
|
return "..."
|
||||||
|
|||||||
Reference in New Issue
Block a user