|
625 | 625 | SIMPLE_STRUCT_HALLUCINATION_FILTER_PROMPT = """ |
626 | 626 | You are a strict, language-preserving memory validator and rewriter. |
627 | 627 |
|
628 | | -Your task is to compare each memory against the provided user messages (the ground truth) and produce a corrected version only when necessary. Always preserve the original language of the memory—do not translate. |
| 628 | +Your task is to eliminate hallucinations and tighten memories by grounding them strictly in the user’s explicit messages. Memories must be factual, unambiguous, and free of any inferred or speculative content. |
629 | 629 |
|
630 | 630 | Rules: |
631 | | -1. **Language Consistency**: The rewritten memory must be in the exact same language as the original input memory. Never switch languages. |
632 | | -2. **Strict Grounding**: Only use information explicitly stated in the user messages. Do not introduce external facts, assumptions, or common sense. |
633 | | -3. **Ambiguity Resolution**: |
634 | | - - Replace vague pronouns (e.g., "he", "it", "they") or unclear references with specific, unambiguous entities based solely on the messages. |
635 | | - - Convert relative time expressions (e.g., "yesterday", "last week", "in two days") into absolute dates or times **only if the messages provide enough context** (e.g., current date is known or implied). |
636 | | -4. **Handling Assistant Inferences**: |
637 | | - - If a memory contains any content **not directly stated by the user**—such as interpretations, summaries, emotional attributions, predictions, causal claims, or generalizations—this is considered an assistant inference. |
638 | | - - In such cases, you **must** set `need_rewrite = true`. |
639 | | - - The `rewritten` text **must explicitly indicate that the statement is an inference**, using a clear and natural prefix in the memory’s language. For English memories, use: |
640 | | - > "The assistant inferred that [rest of the memory]." |
641 | | - - Do **not** present inferred content as factual user statements. |
642 | | -5. **No Rewrite Needed**: If the memory is factually accurate, fully grounded in the messages, unambiguous, and contains no unsupported content, set `need_rewrite = false` and copy the original memory exactly. |
| 631 | +1. **Language Consistency**: Keep the exact original language of each memory—no translation or language switching. |
| 632 | +2. **Strict Factual Grounding**: Include only what the user explicitly stated. Remove or flag anything not directly present in the messages—no assumptions, interpretations, predictions, emotional labels, summaries, or generalizations. |
| 633 | +3. **Ambiguity Elimination**: |
| 634 | + - Replace vague pronouns (e.g., “he”, “it”, “they”) with clear, specific entities **only if** the messages identify them. |
| 635 | + - Convert relative time expressions (e.g., “yesterday”) to absolute dates **only if** the messages provide enough temporal context. |
| 636 | +4. **Hallucination Removal**: |
| 637 | + - If a memory contains **any content not verbatim or directly implied by the user**, it must be rewritten. |
| 638 | + - Do **not** rephrase inferences as facts. Instead, either: |
| 639 | + - Remove the unsupported part and retain only the grounded core, or |
| 640 | + - If the entire memory is ungrounded, mark it for rewrite and make the lack of user support explicit. |
| 641 | +5. **No Change if Fully Grounded**: If the memory is concise, unambiguous, and fully supported by the user’s messages, keep it unchanged. |
643 | 642 |
|
644 | 643 | Inputs: |
645 | 644 | messages: |
|
649 | 648 | {memories_inline} |
650 | 649 |
|
651 | 650 | Output Format: |
652 | | -- Return a JSON object with string keys ("0", "1", "2", ...) corresponding to the input memory indices. |
| 651 | +- Return a JSON object with string keys ("0", "1", "2", ...) matching input memory indices. |
653 | 652 | - Each value must be: {{ "need_rewrite": boolean, "rewritten": string, "reason": string }} |
654 | | -- The "reason" should be concise and specific, e.g.: |
655 | | - - "contains assistant inference not stated by user" |
656 | | - - "pronoun 'it' has no clear referent in messages" |
657 | | - - "relative time 'yesterday' converted to 2025-12-16" |
658 | | - - "accurate and directly supported by user message" |
| 653 | +- The "reason" must be brief and precise, e.g.: |
| 654 | + - "contains unsupported inference" |
| 655 | + - "vague pronoun with no referent in messages" |
| 656 | + - "relative time resolved to 2025-12-16" |
| 657 | + - "fully grounded and concise" |
659 | 658 |
|
660 | | -Important: Output **only** the JSON. No additional text, explanations, markdown, or fields. |
| 659 | +Important: Output **only** the JSON. No extra text, explanations, markdown, or fields. |
661 | 660 | """ |
662 | 661 |
|
663 | 662 |
|
|
0 commit comments