Inferensys

Prompt

Temporal Query Decomposition Prompt

A practical prompt playbook for normalizing relative dates and decomposing complex temporal queries into discrete, independently retrievable sub-questions for time-series RAG systems.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
PROMPT PLAYBOOK

When to Use This Prompt

Identify the retrieval scenarios where temporal query decomposition is required and when simpler approaches suffice.

This prompt is designed for RAG developers and search engineers who manage retrieval over time-series corpora—think financial filings, incident postmortems, news archives, or product changelogs. The core job-to-be-done is converting a user query that contains relative time expressions like 'last quarter,' 'recently,' or 'over the past few months' into a structured set of sub-questions, each with explicit ISO 8601 date boundaries. Without this normalization step, a vector or keyword index has no way to resolve 'last quarter' into a concrete date range, and a single broad query often masks the need to gather evidence from multiple distinct time windows. The ideal user is someone who already has a working retrieval pipeline but finds that temporal queries return incomplete, irrelevant, or temporally misaligned results.

Use this prompt when your retrieval index requires explicit date filters and when a user's temporal question implies multiple independent fact-finding steps. For example, a query like 'How did our Q2 churn rate compare to Q1, and what changed in our onboarding flow during that period?' demands at least two sub-questions targeting different date ranges and potentially different document subsets. The prompt normalizes the relative dates, decomposes the query, and outputs a structured plan that your application can execute as parallel or sequential retrieval calls. It is particularly valuable when your corpus has dense event sequences—such as incident timelines or earnings call transcripts—where a single retrieval pass over a wide date range would bury critical signals in noise.

Do not use this prompt for non-temporal queries, for real-time data streams where dates are irrelevant, or when your underlying search index already performs robust date math natively. If your index can parse 'last quarter' and map it to a filter without external help, adding a decomposition layer adds latency and complexity without benefit. Similarly, avoid this prompt for simple lookups like 'Show me the Q3 report'—a direct metadata filter is faster and more reliable. The next section provides the copy-ready prompt template you can adapt, followed by guidance on wiring it into your retrieval harness with validation, retries, and failure mode handling.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Temporal Query Decomposition Prompt works and where it introduces risk. Use these cards to decide if this prompt fits your retrieval architecture.

01

Good Fit: Time-Series Corpora

Use when: your knowledge base contains dated documents such as financial reports, news archives, or release notes where temporal boundaries change answer correctness. Why: relative terms like 'last quarter' must resolve to concrete date ranges before retrieval, and splitting the query by time period prevents cross-contamination of evidence from different eras.

02

Bad Fit: Static Reference Material

Avoid when: your corpus has no meaningful temporal dimension, such as a static API reference or a single-edition manual. Risk: the decomposition step adds latency and token cost without improving retrieval precision. The validator may flag false-positive date-range errors when no temporal constraints exist.

03

Required Inputs

Required: a user query containing at least one relative or absolute time expression, plus a known corpus date range. Optional but recommended: a reference date for resolving relative terms like 'now' or 'current.' Guardrail: if the query contains no temporal signal, skip decomposition and route to a standard retrieval path to avoid unnecessary processing.

04

Operational Risk: Date Boundary Drift

Risk: the model normalizes relative dates incorrectly, producing sub-queries with overlapping or gapped date ranges that miss relevant documents or retrieve duplicates. Guardrail: run the output through a date-range validator that checks for gaps, overlaps, and out-of-corpus bounds before executing retrieval. Log boundary mismatches for prompt refinement.

05

Operational Risk: Over-Decomposition

Risk: a simple temporal query like 'What happened in March?' is split into dozens of daily sub-queries, overwhelming the retrieval pipeline with redundant calls. Guardrail: set a maximum sub-query limit based on your retrieval budget and use a granularity heuristic that matches the query's specificity. Coarse queries get coarse periods.

06

Integration Point: Pre-Retrieval Harness

Use when: this prompt sits between the user input and your retrieval backend as a query rewriting step. Guardrail: treat the decomposed sub-queries as an ordered batch. Run retrieval for each sub-query, deduplicate results by document ID, and merge evidence with source timestamps before passing to the answer generation step.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt that decomposes a temporal user query into sub-questions with explicit date ranges, ready for adaptation and integration into your RAG pipeline.

This prompt template is designed to be copied directly into your application's prompt management system. It takes a user query containing relative or absolute time references and breaks it into a set of independently answerable sub-questions, each scoped to a specific date range. The model is instructed to normalize all temporal expressions into explicit ISO 8601 date boundaries, which is critical for downstream retrieval systems that cannot interpret phrases like "last quarter" or "recently." Before using this template, replace every square-bracket placeholder with the values appropriate for your application, model, and risk tolerance.

text
You are a temporal query decomposition assistant. Your job is to take a user's question that contains time-based references and break it into a set of sub-questions, each with an explicit date range. Normalize all relative time expressions (e.g., "last month," "recently," "this year") into concrete ISO 8601 date boundaries (YYYY-MM-DD).

[CONTEXT]

Today's date: [CURRENT_DATE]

[INPUT]

User query: [USER_QUERY]

[OUTPUT_SCHEMA]

Return a JSON object with the following structure:
{
  "original_query": "string",
  "decomposition_strategy": "parallel | sequential",
  "sub_questions": [
    {
      "id": "string",
      "question": "string",
      "start_date": "YYYY-MM-DD",
      "end_date": "YYYY-MM-DD",
      "rationale": "string explaining why this date range was chosen",
      "depends_on": ["sub_question_id"] | []
    }
  ]
}

[CONSTRAINTS]

- Every sub_question must have non-null start_date and end_date fields.
- If the user query contains no temporal references, return a single sub_question with start_date and end_date set to null and explain in the rationale that no temporal constraint was detected.
- If a relative time expression is ambiguous (e.g., "this quarter" when near a quarter boundary), choose the most likely interpretation and note the ambiguity in the rationale.
- Sub-questions must be independently answerable unless depends_on is populated.
- Do not answer the user's question. Only decompose it.
- If the query spans multiple non-contiguous time periods, generate one sub-question per period.

[EXAMPLES]

Example 1:
User query: "How did our revenue change between Q1 and Q2 of 2024?"
Output:
{
  "original_query": "How did our revenue change between Q1 and Q2 of 2024?",
  "decomposition_strategy": "parallel",
  "sub_questions": [
    {
      "id": "q1",
      "question": "What was our revenue in Q1 2024?",
      "start_date": "2024-01-01",
      "end_date": "2024-03-31",
      "rationale": "Q1 2024 spans January 1 to March 31, 2024.",
      "depends_on": []
    },
    {
      "id": "q2",
      "question": "What was our revenue in Q2 2024?",
      "start_date": "2024-04-01",
      "end_date": "2024-06-30",
      "rationale": "Q2 2024 spans April 1 to June 30, 2024.",
      "depends_on": []
    }
  ]
}

Example 2:
User query: "What were the top support issues last week and how do they compare to the week before?"
Output:
{
  "original_query": "What were the top support issues last week and how do they compare to the week before?",
  "decomposition_strategy": "parallel",
  "sub_questions": [
    {
      "id": "last_week",
      "question": "What were the top support issues last week?",
      "start_date": "2025-01-13",
      "end_date": "2025-01-19",
      "rationale": "Assuming today is 2025-01-20, last week is Monday January 13 through Sunday January 19.",
      "depends_on": []
    },
    {
      "id": "week_before",
      "question": "What were the top support issues the week before last?",
      "start_date": "2025-01-06",
      "end_date": "2025-01-12",
      "rationale": "The week before last week is Monday January 6 through Sunday January 12.",
      "depends_on": []
    }
  ]
}

[RISK_LEVEL]

[RISK_LEVEL]

To adapt this template, start by populating [CURRENT_DATE] with the actual date at query time, formatted as YYYY-MM-DD. This is the single most important variable because all relative date normalization depends on it. Replace [USER_QUERY] with the incoming user question from your application. The [CONTEXT] placeholder can be used to inject additional information such as the user's timezone, fiscal calendar definitions, or company-specific period boundaries. If your application operates in a regulated domain where date misinterpretation could cause financial or compliance errors, set [RISK_LEVEL] to "high" and add an instruction requiring the model to flag ambiguous temporal expressions for human review rather than guessing.

After copying the template, test it against a small set of queries that include edge cases: queries with no time references, queries spanning multiple years, queries with ambiguous boundaries like "this month" when the current date is the first or last day of the month, and queries that mix absolute and relative dates. Validate that every returned sub-question has a start_date and end_date that are either both null or both populated with valid ISO 8601 strings. If you are wiring this into a production RAG pipeline, add a post-processing validator that rejects any decomposition where a sub-question's end_date is before its start_date, where date ranges overlap in a sequential decomposition, or where a depends_on field references a non-existent sub-question ID. These structural checks catch model errors before they propagate into your retrieval layer and produce silently wrong answers.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Temporal Query Decomposition Prompt. Each placeholder must be populated before the prompt is sent to the model. Missing or malformed variables cause date-range boundary errors and incomplete sub-question generation.

PlaceholderPurposeExampleValidation Notes

[USER_QUERY]

The original temporal question to decompose

What were our Q3 revenue trends compared to last year?

Must contain at least one time expression. Reject empty or null input. Check for relative date terms like 'last quarter' or 'recent'.

[REFERENCE_DATE]

The anchor date for resolving relative time expressions

2025-04-08

Must be ISO 8601 date format YYYY-MM-DD. Required. If null, prompt must abort with a clear error. Do not default to system date without explicit user confirmation.

[CORPUS_DATE_RANGE]

The known date boundaries of the retrieval corpus

2020-01-01 to 2025-03-31

Must be two ISO 8601 dates separated by ' to '. Required. Used to validate that generated sub-question date ranges fall within available data. Reject if start date is after end date.

[OUTPUT_SCHEMA]

JSON schema definition for the expected sub-question output

{ "sub_questions": [{ "id": "string", "query": "string", "date_range_start": "date", "date_range_end": "date", "dependency": "string or null" }] }

Must be a valid JSON schema object. Parse check required before prompt assembly. Each sub-question must include date_range_start and date_range_end fields.

[MAX_SUB_QUESTIONS]

Upper limit on the number of sub-questions to generate

5

Must be an integer between 2 and 10. Prevents runaway decomposition. If the query requires more periods, the prompt should prioritize the most salient ranges.

[TIMEZONE_OFFSET]

UTC offset for the user's locale to resolve day-boundary queries

+00:00

Must match regex ^[+-]\d{2}:\d{2}$. Default to +00:00 if unknown. Affects 'today', 'yesterday', and hour-level precision. Log a warning if not explicitly provided.

[GRANULARITY_HINT]

Preferred time granularity for decomposition

month

Must be one of: day, week, month, quarter, year. Guides how the prompt splits date ranges. If null, the prompt should infer from the query. Validation: enum check against allowed values.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Temporal Query Decomposition Prompt into a production RAG pipeline with validation, retries, and date-range boundary checks.

The Temporal Query Decomposition Prompt is designed to be called as a pre-retrieval step in a RAG pipeline. When a user query contains relative time expressions like 'last quarter', 'recent', or 'since the announcement', the prompt normalizes those into explicit date ranges and splits the query into sub-questions targeting distinct time periods. The harness should intercept the user query, detect whether temporal decomposition is needed (via a lightweight classifier or keyword check), and then call the LLM with this prompt before any retrieval occurs. The output is a structured list of sub-questions, each with a start_date and end_date field that downstream retrieval systems can use as metadata filters.

The implementation must include a date-range validator that runs immediately after the LLM response. This validator checks that every generated sub-question has non-null start_date and end_date fields, that start_date is before end_date, that date ranges do not overlap unless the decomposition explicitly calls for comparative periods, and that all dates fall within the corpus boundary defined in [CORPUS_DATE_RANGE]. If validation fails, the harness should retry the prompt once with the validation error appended to [CONSTRAINTS]. After two failures, escalate to a human reviewer or fall back to a default single-query rewrite. Log every decomposition attempt, including the original query, generated sub-questions, validator results, and retry count, for observability.

For model choice, use a model with strong instruction-following and JSON output capabilities, such as GPT-4o, Claude 3.5 Sonnet, or a fine-tuned variant if your temporal expressions are domain-specific. Set temperature=0 to maximize deterministic date normalization. If your RAG system uses multiple retrieval backends (e.g., vector search for semantic matches and a date-filtered keyword index for time-bound documents), map each sub-question to the appropriate backend based on its target_index field. Wire the sub-questions into a parallel retrieval step, then feed the collected evidence into a downstream synthesis prompt. Avoid feeding raw sub-questions directly to the user; they are intermediate artifacts for retrieval orchestration.

IMPLEMENTATION TABLE

Expected Output Contract

Strict JSON schema for temporal sub-questions. Use this contract to validate model output before passing sub-questions to retrieval backends.

Field or ElementType or FormatRequiredValidation Rule

sub_questions

Array of objects

Must be a non-empty array. Reject if length is 0 or field is missing.

sub_questions[].id

String, kebab-case

Must match pattern ^sq-[a-z0-9-]+$. Must be unique within the array.

sub_questions[].query_text

String

Must be non-empty. Must contain at least one explicit date, date range, or temporal constraint (e.g., 'Q1 2024', 'March 2023', 'before 2020'). Reject if temporal reference is only relative (e.g., 'recent').

sub_questions[].date_range_start

ISO 8601 date string (YYYY-MM-DD) or null

If provided, must be a valid ISO 8601 date. If null, the sub-question has an open start boundary. Must be <= date_range_end if both are provided.

sub_questions[].date_range_end

ISO 8601 date string (YYYY-MM-DD) or null

If provided, must be a valid ISO 8601 date. If null, the sub-question has an open end boundary. Must be >= date_range_start if both are provided.

sub_questions[].dependency_id

String or null

If not null, must match the id of a preceding sub_question in the array. Reject if dependency_id references a later or non-existent sub-question. Use null for independent sub-questions.

sub_questions[].expected_evidence_type

Enum: 'event', 'metric', 'state', 'trend', 'comparison'

Must be one of the listed enum values. Reject any other value. Used by downstream retrieval to select appropriate index or search strategy.

original_query_date_range

Object with 'start' and 'end' ISO 8601 date strings or null

Must reflect the normalized date range of the original user query. If the original query had no temporal constraint, both fields must be null. If one boundary is implied (e.g., 'since 2022'), the other must be null. Reject if start > end.

PRACTICAL GUARDRAILS

Common Failure Modes

Temporal queries break in predictable ways. Here are the most common failure modes when decomposing time-sensitive questions and how to guard against them in production.

01

Relative Date Anchoring Drift

What to watch: The model resolves 'last quarter' or 'recently' relative to its training cutoff date instead of the current system timestamp. Sub-questions inherit wrong absolute date ranges, retrieving irrelevant or stale documents. Guardrail: Always inject the current date as [CURRENT_DATE] in the system prompt and require the model to output resolved absolute date ranges. Validate that every generated date range falls within a reasonable window of the provided timestamp.

02

Implicit Time Zone Assumptions

What to watch: Queries like 'yesterday's incidents' or 'end of day reports' resolve to UTC when the user expects their local time zone. This shifts date boundaries and causes missing or off-by-one-day retrieval results. Guardrail: Require a [TIMEZONE] input variable. Include a validation step that checks whether generated date boundaries align with the user's business hours or operational time zone before retrieval executes.

03

Overlapping or Duplicate Sub-Questions

What to watch: The decomposition produces multiple sub-questions with nearly identical date ranges, causing redundant retrieval and wasted compute. This happens when the model fails to recognize that 'Q1 2024' and 'January through March 2024' are the same interval. Guardrail: Add a deduplication step that normalizes all generated date ranges to a canonical format and merges sub-questions whose date boundaries overlap by more than a configurable threshold.

04

Missing Boundary Edge Cases

What to watch: A query like 'changes between March and June' is ambiguous about whether March and June are inclusive or exclusive. The model guesses, and the resulting sub-questions either double-count boundary periods or leave gaps. Guardrail: Enforce explicit boundary markers in the output schema. Require each sub-question to declare start_inclusive and end_inclusive boolean fields. Add a validator that checks for gaps or overlaps across all generated intervals.

05

Temporal Granularity Mismatch

What to watch: The user asks for 'monthly trends' but the decomposition generates daily sub-questions, or the user asks for 'daily metrics' and gets quarterly buckets. The retrieval index is queried at the wrong granularity, returning too much noise or too little signal. Guardrail: Detect the temporal granularity from the user query and constrain sub-question date ranges to match. Include a granularity field in the output schema and validate that all generated intervals align to the declared granularity.

06

Event Sequence Ordering Errors

What to watch: For queries about event sequences like 'what happened after the outage,' the model generates sub-questions with incorrect chronological ordering or fails to enforce that later sub-questions depend on answers from earlier ones. Guardrail: Require a sequence_order field in the output schema. Validate that sub-question date ranges are strictly non-decreasing when sequence dependencies exist. Add a dependency check that prevents executing a later sub-question before its predecessor returns results.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the quality of decomposed temporal sub-questions before integrating them into a production RAG pipeline. Each criterion targets a specific failure mode common in time-series retrieval.

CriterionPass StandardFailure SignalTest Method

Date Normalization

All relative dates (e.g., 'last month', 'Q1') are resolved to explicit ISO 8601 date ranges in each sub-question.

Sub-questions contain unresolved relative terms like 'recently' or 'this quarter'.

Parse output for ISO 8601 date strings; flag any sub-question missing a concrete range.

Temporal Boundary Correctness

Date ranges in sub-questions do not overlap incorrectly and collectively cover the full original query period without gaps.

Adjacent sub-questions have overlapping date ranges or leave a gap between periods.

Sort sub-questions by start date; assert end_date[i] < start_date[i+1] and total span matches original query range.

Sub-Question Independence

Each sub-question can be answered independently from a single time-bounded retrieval without requiring results from another sub-question.

A sub-question references another sub-question's output or uses a relative temporal anchor like 'after the previous event'.

Execute each sub-question against a mock retriever; verify no cross-dependencies in query text.

Coverage of Original Intent

The set of sub-questions collectively addresses every temporal aspect and entity mentioned in the original query.

An entity, event, or time period from the original query is missing from the sub-question set.

Diff entities and time expressions in original query against those in generated sub-questions; flag omissions.

Granularity Appropriateness

Time granularity (day, week, month, quarter) matches the query's implied precision and the corpus's temporal resolution.

Sub-questions use daily granularity for a query about annual trends, or yearly granularity for a query about hourly events.

Check sub-question date range span against a configured max/min granularity threshold for the target corpus.

Event Sequence Ordering

If the original query implies a sequence of events, sub-questions are ordered chronologically and labeled with sequence position.

Event-driven sub-questions are generated in random order or missing sequence metadata.

Inspect sub-question list for a 'sequence_position' field; assert values are monotonically increasing integers starting from 1.

Output Schema Compliance

Every sub-question object includes required fields: query_text, start_date, end_date, and sequence_position.

A sub-question object is missing a required field or contains an incorrectly typed value.

Validate output JSON against the defined schema; reject on missing fields or type mismatches.

No Future Date Leakage

No sub-question includes a date range extending beyond the current date unless the original query explicitly requests forecasting.

A sub-question has an end_date in the future for a historical query.

Compare all end_date values against current system date; flag any future dates for non-forecast queries.

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a frontier model and minimal validation. Remove the strict JSON output schema and ask for a plain list of sub-questions with date ranges. Accept natural-language date normalization without enforcing boundary checks.

code
Break down the temporal query: [USER_QUERY]
Today's date: [CURRENT_DATE]

List each sub-question with its target time period.

Watch for

  • Relative dates like "last month" resolving incorrectly near month boundaries
  • Overlapping or gapped date ranges between sub-questions
  • Model inventing specific dates when the query is vague
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.