Skip to content

fix: inject current date into summary prompt to prevent AI temporal confusion#2529

Open
ursazoo wants to merge 1 commit intokarakeep-app:mainfrom
ursazoo:fix/inject-current-date-in-summary-prompt
Open

fix: inject current date into summary prompt to prevent AI temporal confusion#2529
ursazoo wants to merge 1 commit intokarakeep-app:mainfrom
ursazoo:fix/inject-current-date-in-summary-prompt

Conversation

@ursazoo
Copy link
Copy Markdown

@ursazoo ursazoo commented Feb 28, 2026

Problem

When the AI model generates summaries, it doesn't know the current date. This causes it to incorrectly flag recent dates in articles (e.g., "2026 ClawHub trending list") as potentially erroneous in the summary's "questionable claims" section, because the model reasons from its training cutoff year rather than the actual current date.

Solution

Inject today's date (new Date().toISOString().split('T')[0]) into constructSummaryPrompt as an explicit rule. This is computed at runtime so it always reflects the server's actual current date.

+  const today = new Date().toISOString().split("T")[0];
   return `
 Summarize the following content responding ONLY with the summary. You MUST follow the following rules:
 - Summary must be in 3-4 sentences.
 - The summary must be in ${lang}.
+- Today's date is ${today}. Do NOT flag or question dates that are in the past relative to today.

Changes

  • packages/shared/prompts.ts: Added current date injection in constructSummaryPrompt

Test plan

  • Generate a summary for an article that mentions a recent year (e.g., 2025 or 2026)
  • Verify the AI no longer flags those dates as "potentially incorrect" in the summary

AI 模型在生成摘要时不知道当前日期,会将文章中提到的近期日期(如2026年)
误判为"未来时间点,可能有误"。在 constructSummaryPrompt 中注入当前日期,
让模型准确判断文章中的时间引用是否真正过时。
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 28, 2026

Walkthrough

The pull request adds a new local constant capturing today's ISO date to the constructSummaryPrompt function and incorporates it into the returned prompt with a rule about not flagging past dates.

Changes

Cohort / File(s) Summary
Prompt Enhancement
packages/shared/prompts.ts
Added local constant for today's ISO date and incorporated it into prompt content with rule about past dates; function signature remains unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: injecting the current date into the summary prompt to prevent the AI from incorrectly flagging recent dates.
Description check ✅ Passed The description is well-organized and directly related to the changeset, explaining the problem, solution, specific code changes, and test plan for the date injection feature.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/shared/prompts.ts (1)

76-76: Consider making the date injectable for deterministic tests.

Line 76 makes prompt output time-dependent; an optional today parameter (with the current expression as default) keeps runtime behavior while making tests/snapshots stable.

♻️ Proposed refactor
 export function constructSummaryPrompt(
   lang: string,
   customPrompts: string[],
   content: string,
+  today: string = new Date().toISOString().split("T")[0],
 ): string {
-  const today = new Date().toISOString().split("T")[0];
   return `
 Summarize the following content responding ONLY with the summary. You MUST follow the following rules:
 - Summary must be in 3-4 sentences.
 - The summary must be in ${lang}.
 - Today's date is ${today}. Do NOT flag or question dates that are in the past relative to today.
 ${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")}
     ${content}`;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/shared/prompts.ts` at line 76, Replace the hard-coded today value
with an injectable optional parameter so prompts are deterministic: change the
local constant initialization (const today = new
Date().toISOString().split("T")[0];) to accept a parameter (e.g., today?: string
= new Date().toISOString().split("T")[0]) on the function that constructs the
prompt in packages/shared/prompts.ts, use that parameter where the current today
variable is referenced, and update callers/tests to pass a fixed date in unit
tests while leaving runtime callers to rely on the default.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/shared/prompts.ts`:
- Line 76: Replace the hard-coded today value with an injectable optional
parameter so prompts are deterministic: change the local constant initialization
(const today = new Date().toISOString().split("T")[0];) to accept a parameter
(e.g., today?: string = new Date().toISOString().split("T")[0]) on the function
that constructs the prompt in packages/shared/prompts.ts, use that parameter
where the current today variable is referenced, and update callers/tests to pass
a fixed date in unit tests while leaving runtime callers to rely on the default.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec2d037 and d313932.

📒 Files selected for processing (1)
  • packages/shared/prompts.ts

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Feb 28, 2026

Greptile Summary

This PR fixes an issue where AI models generating article summaries would incorrectly flag recent dates (like "2026") as questionable because they don't know the current date and reason from their training cutoff year. The fix injects the current date into the constructSummaryPrompt function, computed at runtime using new Date().toISOString().split("T")[0], and explicitly instructs the AI not to flag dates that are in the past.

Key changes:

  • Added date computation at the start of constructSummaryPrompt
  • Injected a new prompt rule informing the AI of today's date and instructing it not to flag past dates as questionable
  • Uses UTC date (ISO format) for consistency across all server executions

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is small, focused, and directly addresses the stated problem. It adds a date calculation and one additional instruction to the AI prompt. The implementation is clean and uses standard JavaScript Date APIs. Since this function is used server-side (in prompts.server.ts), there are no client-side concerns. The approach is straightforward and unlikely to introduce bugs.
  • No files require special attention

Important Files Changed

Filename Overview
packages/shared/prompts.ts Added current date injection to summary prompt to prevent AI from flagging recent dates as questionable

Last reviewed commit: d313932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant