Skip to content

Fix(chat): resolve stale system-prompt date with explicit per-call evaluation#451

Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-47
Open

Fix(chat): resolve stale system-prompt date with explicit per-call evaluation#451
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-47

Conversation

@Jean-Regis-M
Copy link
Copy Markdown
Contributor

Summary

Fixes #442 stale date in system prompt for long-lived sessions crossing midnight.

_get_system_prompt() now captures current_date as an explicit local variable at method entry in both VendorChatAssistant and CoPilotAssistant, guaranteeing a fresh date on every call.


Problem

datetime.now(UTC) was evaluated inline inside the f-string. While this works for single calls, it provides no structural guarantee of re-evaluation across conversation turns. Any future caching of the prompt string or a session spanning midnight would carry a stale date for the remainder of the day, producing off-by-one-day errors in financial reports and scheduling responses.

Root Cause

Implicit evaluation order: the date was computed inside the f-string with no contract enforcing re-evaluation per call.

# Before  date baked into f-string, no explicit re-evaluation guarantee
f"Today's date is {datetime.now(UTC).strftime('%Y-%m-%d')}."

Solution

Extract date computation into a named local variable at the top of _get_system_prompt() in both assistants, then reference it in the f-string.

# After  date captured explicitly at method entry, once per call
current_date = datetime.now(UTC).strftime("%Y-%m-%d")
f"Today's date is {current_date}."

This makes the evaluation point structurally explicit and immune to any prompt-string caching introduced later.

Files changed: vendor_chat_assistant.py, copilot_assistant.py 4 lines total.


Impact

Area Detail
Single calls No behavioral change
Long-lived sessions Date is now always fresh per turn
Breaking changes None
Regression risk Zero existing date-format tests pass unchanged

Testing

pytest tests/unit/agents/test_chat_assistant.py::TestVendorSystemPrompt::test_chat_prompt_005_vendor_prompt_contains_current_date -v
pytest tests/unit/agents/test_chat_assistant.py::TestCoPilotPromptExtended::test_chat_prompt_040_copilot_prompt_date_format_is_iso -v

Tasks

  • Extract current_date local variable in VendorChatAssistant._get_system_prompt()
  • Extract current_date local variable in CoPilotAssistant._get_system_prompt()
  • Replace inline datetime.now() f-string expressions with {current_date}
  • Verify existing date-format unit tests pass without modification

Root cause:
datetime.now(UTC) embedded directly in f-string makes evaluation
order implicit and fragile under accidental prompt caching.

Solution:
Extract to `current_date` local at the top of each _get_system_prompt()
call in VendorChatAssistant and CoPilotAssistant. Evaluation now occurs
explicitly at method entry, making per-call freshness structurally
visible and independently testable.

Impact:
Zero behavioral change for single calls; eliminates stale-date risk
for long-lived sessions spanning midnight. No breaking changes.

Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
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.

Bug_199_EVALUATE: PROMPT-FUNC-001 — Current date in system prompt goes stale for long-running sessions

1 participant