WOTD _polish: enforce the "examples must use the word" contract
Per Codex audit: only accept a polish when there's a gloss AND at least one example sentence that actually contains the word (case-insensitive). Examples that don't use the word are dropped; if none remain, fall back to the raw dictionary def/examples instead of shipping a gloss with empty/irrelevant usage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+4
-1
@@ -95,7 +95,10 @@ def _polish(client, word: str, part_of_speech: str | None, definition: str) -> d
|
||||
return None
|
||||
gloss = " ".join(str(data.get("gloss") or "").split()).strip()
|
||||
examples = [" ".join(str(e).split()).strip() for e in (data.get("examples") or []) if str(e).strip()]
|
||||
if not gloss:
|
||||
# Enforce the contract: keep only sentences that actually use the word, and require at
|
||||
# least one. A gloss with no usable examples falls back to the raw dictionary data.
|
||||
examples = [e for e in examples if word.lower() in e.lower()]
|
||||
if not gloss or not examples:
|
||||
return None
|
||||
return {"gloss": gloss, "examples": examples[:2]}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user