Skip to content

Add current date to query rewrite and chat answer prompts - #3068

Open
John CSA (jluocsa) wants to merge 8 commits into
Azure-Samples:mainfrom
jluocsa:feature/current-date-prompts
Open

Add current date to query rewrite and chat answer prompts#3068
John CSA (jluocsa) wants to merge 8 commits into
Azure-Samples:mainfrom
jluocsa:feature/current-date-prompts

Conversation

@jluocsa

@jluocsa John CSA (jluocsa) commented May 30, 2026

Copy link
Copy Markdown
Contributor

Purpose

Fixes #2952.

The LLM has no inherent knowledge of the current date, so it cannot reason about
relative time references such as "today", "last week", "this month", or "current"
in either query rewriting or answer generation. This PR injects the current date
into both the query rewrite prompt and the chat answer prompt so the model can
resolve relative time references into concrete terms.

Changes:

  • Added Approach.get_current_date() which returns today's date formatted as e.g.
    February 3, 2026.
  • Pass a current_date variable into:
    • the chat answer system prompt (run_until_final_call),
    • the query rewrite prompt in chatreadretrieveread.py (run_search_approach),
    • the agentic query rewrite prompt in approach.py.
  • Updated chat_answer.system.jinja2 and query_rewrite.system.jinja2 to render a
    date instruction only when current_date is provided ({% if current_date %}),
    so existing behavior is unchanged when the variable is absent.
  • Added 4 tests in tests/test_chatapproach.py covering presence/absence of the
    date in the rendered prompts and the date format.

Does this introduce a breaking change?

[ ] Yes
[x] No

The prompt additions are guarded by {% if current_date %}, so prompts render
identically when the variable is not supplied.

Does this require changes to learn.microsoft.com docs?

[ ] Yes
[x] No

Type of change

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

Code quality checklist

  • The current tests all pass (python -m pytest).
  • I added tests that prove my fix is effective or that my feature works
  • I ran python -m pytest --cov to verify 100% coverage of added lines
  • I ran ty check to check for type errors
  • I either used the pre-commit hooks or ran ruff and black manually on my code.

@pamelafox

Copy link
Copy Markdown
Collaborator

I love this change, thank you for making it - I've been meaning to add the date for a while. I'll verify it locally as well and run some evals too, since it changes the prompt.

@pamelafox

Copy link
Copy Markdown
Collaborator

John CSA (@jluocsa) I think the pytest snapshots haven't been updated? See the failing CI.

@pamelafox Pamela Fox (pamelafox) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please update snapshot tests

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.

Add current date to query rewrite and chat answer prompts

2 participants