This prompt is designed for a single, high-precision job: converting a natural language date range expression into a strict, machine-readable canonical form. The target user is a backend engineer, data pipeline operator, or booking system developer who needs to ingest user-provided strings like 'Jan 5-12, 2025', 'Q1 2024', or 'the last week of March' and produce a deterministic start_timestamp, end_timestamp, and inclusivity flags. The primary value is eliminating ambiguity before the data enters a database, search index, or scheduling system where inconsistent date logic causes downstream query failures and reporting errors.
Prompt
Date Range Parsing and Canonicalization Prompt Template

When to Use This Prompt
Define the job, ideal user, required context, and constraints for the Date Range Parsing and Canonicalization prompt.
You should use this prompt when the input is a single, self-contained range expression and the required output is a structured object suitable for direct use in an API call or database write. The prompt assumes you have already isolated the date range string from the rest of the user's message. It is not designed for extracting multiple date ranges from a long document, resolving relative expressions that require a dynamic anchor timestamp (e.g., 'next Friday'), or validating dates against complex business rules like holiday calendars. For those tasks, use the sibling playbooks on Timestamp Extraction from Unstructured Text, Relative Date Expression Resolution, or Date Validation Against Business Rules, respectively. This prompt also does not handle timezone conversion; it expects the caller to provide a [REFERENCE_TIMEZONE] if the input lacks one.
Do not use this prompt for open-ended date parsing where the input format is completely unknown. The model performs best when it receives a clear range expression. If you are building a general-purpose date input field that accepts single dates, ranges, and relative expressions, you should first classify the input type using a routing prompt, then dispatch to this playbook only for range expressions. For production systems, always pair this prompt with a post-processing validation layer that checks the output against a JSON Schema, verifies that start_timestamp is before end_timestamp, and logs any confidence score below your threshold for human review. The next section provides the copy-ready template you can adapt and deploy.
Use Case Fit
Where this prompt works and where it does not. Date range parsing is deceptively hard—natural language is ambiguous, boundary conditions are subtle, and downstream systems expect strict contracts.
Good Fit: Structured Range Expressions
Use when: inputs contain explicit date ranges like 'Jan 5-12, 2025', 'Q1 2024', 'March 1 to March 15', or '2025-W03'. These have clear start and end points that map to canonical timestamps. Guardrail: validate that the output contains both start and end timestamps with correct inclusivity flags before accepting.
Bad Fit: Vague or Subjective Ranges
Avoid when: inputs contain expressions like 'sometime next month', 'around the holidays', 'early 2025', or 'the week after next'. These require interpretation that may vary by user, locale, or business context. Guardrail: route ambiguous inputs to a clarification prompt or return a confidence score below threshold to trigger human review.
Required Inputs
Must provide: the raw date range expression string, a reference timestamp for relative anchoring, and a target timezone. Optional but recommended: business rules for boundary interpretation (inclusive/exclusive defaults), locale context for week-start conventions, and a list of known holidays if holiday-aware parsing is needed. Guardrail: reject inputs that lack a reference timestamp when the expression contains relative terms.
Operational Risk: Boundary Ambiguity
Risk: expressions like 'Jan 5-12' may mean inclusive of both endpoints, exclusive of the end, or something else entirely. Different downstream systems (booking engines, reporting pipelines, billing systems) have different expectations. Guardrail: always emit explicit inclusivity flags per endpoint. Validate against the target system's boundary contract before ingestion. Add a human-approval step for ranges that affect financial or compliance calculations.
Operational Risk: Timezone Drift
Risk: a range like 'Jan 5, 2025' resolved in UTC may produce different calendar-day boundaries than the user's local timezone, causing off-by-one errors in reporting or booking windows. Guardrail: require an explicit timezone parameter. Never assume UTC silently. Include the timezone in the output timestamps and log it for audit. Test with timezones that cross the international date line.
Operational Risk: Malformed Input Cascades
Risk: a single unparseable range expression in a batch can cause the entire pipeline to fail or, worse, silently produce incorrect timestamps that corrupt downstream aggregations. Guardrail: implement per-record error isolation. Return a structured error object with the original input, failure reason, and a null range rather than halting the batch. Monitor error rates and set alerts for spikes in unparseable inputs.
Copy-Ready Prompt Template
A reusable prompt template with square-bracket placeholders for parsing and canonicalizing date range expressions into structured start and end timestamps.
This template is the core instruction set for converting natural language date range expressions into a machine-readable canonical form. It accepts a free-text range expression, an optional reference timestamp, and a target timezone, then produces a JSON object containing the resolved start and end timestamps in ISO 8601 format, along with inclusivity flags and a parse confidence indicator. The template is designed to be dropped directly into a system prompt or a user message for any capable LLM, with placeholders that your application layer fills at runtime.
codeSYSTEM: You are a precise date range parser. Your only job is to convert a natural language date range expression into a canonical start and end timestamp. INPUTS: - Range Expression: [RANGE_EXPRESSION] - Reference Timestamp (optional, ISO 8601): [REFERENCE_TIMESTAMP] - Target Timezone (IANA format, e.g., 'America/New_York'): [TARGET_TIMEZONE] OUTPUT_SCHEMA: { "start": "ISO 8601 timestamp or null", "end": "ISO 8601 timestamp or null", "start_inclusive": true or false, "end_inclusive": true or false, "confidence": 0.0 to 1.0, "resolution_notes": "string explaining how the range was interpreted" } CONSTRAINTS: - If the range expression is ambiguous, choose the most common interpretation and note the ambiguity in resolution_notes. - If the expression cannot be parsed, set start and end to null and confidence to 0.0. - For open-ended ranges (e.g., 'since March'), set the missing boundary to null. - For relative expressions (e.g., 'last week'), resolve them relative to the reference timestamp. If no reference is provided, use the current UTC time. - All output timestamps must include a timezone offset. - Do not invent dates that are not implied by the input. EXAMPLES: Input: "Jan 5-12, 2025" Output: {"start": "2025-01-05T00:00:00-05:00", "end": "2025-01-12T23:59:59-05:00", "start_inclusive": true, "end_inclusive": true, "confidence": 0.98, "resolution_notes": "Interpreted as full days in the target timezone. End set to end of day."} Input: "Q1 2024" Output: {"start": "2024-01-01T00:00:00-05:00", "end": "2024-03-31T23:59:59-04:00", "start_inclusive": true, "end_inclusive": true, "confidence": 0.99, "resolution_notes": "Standard calendar quarter. End boundary accounts for DST transition."} Input: "next Friday" Output: {"start": "2025-03-28T00:00:00-04:00", "end": "2025-03-28T23:59:59-04:00", "start_inclusive": true, "end_inclusive": true, "confidence": 0.95, "resolution_notes": "Resolved relative to reference timestamp 2025-03-24T12:00:00Z. 'Next' interpreted as the upcoming Friday."}
To adapt this template, replace the placeholders with values from your application context. [RANGE_EXPRESSION] is the user-provided or system-extracted text. [REFERENCE_TIMESTAMP] should be injected as the current server time or the relevant anchor point for relative expressions. [TARGET_TIMEZONE] must be resolved from user preferences, account settings, or a sensible default—never hardcode it. The OUTPUT_SCHEMA block is your contract with downstream code; validate the JSON structure before acting on the result. If your use case requires only dates without times, adjust the schema and constraints accordingly, but keep the inclusivity flags to avoid off-by-one errors in range queries.
Before deploying, test this template against a golden set of range expressions that includes absolute ranges, relative ranges, open-ended ranges, and malformed inputs. Pay special attention to DST boundary crossings, month-length edge cases, and expressions like 'end of month' where the resolved timestamp depends on the reference date. If the prompt will be used in a booking or billing system, add a post-processing validation step that rejects any output where confidence is below your threshold—typically 0.85—and escalates for human review or asks the user to rephrase.
Prompt Variables
Required and optional inputs for the Date Range Parsing and Canonicalization prompt. Validate each input before calling the model to prevent cascading failures in booking systems and reporting pipelines.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[DATE_RANGE_EXPRESSION] | The raw date range string to parse and canonicalize | Jan 5-12, 2025 | Required. Must be non-empty. Reject if null or whitespace-only. Length check: 1-500 characters. |
[REFERENCE_TIMESTAMP] | Anchor timestamp for resolving relative expressions like 'this week' or 'next quarter' | 2025-01-08T14:30:00Z | Required. Must be valid ISO 8601. If not provided, default to current UTC time. Validate parseability before prompt assembly. |
[TIMEZONE] | IANA timezone for interpreting ambiguous local-time expressions | America/New_York | Required. Must match IANA timezone database. Reject unknown timezones. Default to 'UTC' if unspecified. |
[OUTPUT_SCHEMA] | Expected JSON schema for the canonicalized output | {"start": "ISO 8601", "end": "ISO 8601", "inclusive_start": true, "inclusive_end": false} | Required. Must include start, end, and inclusivity flags. Validate schema is valid JSON before injection. |
[BUSINESS_RULES] | Domain-specific constraints such as future-only ranges or maximum range span | max_span_days: 365, allow_past_ranges: false | Optional. If provided, must be valid JSON object. Null allowed. Rules are applied post-canonicalization in validation layer. |
[LOCALE_HINTS] | Locale context for disambiguating date ordering conventions | en-US | Optional. Use ISO language-region format. Null allowed. Helps resolve MM/DD vs DD/MM ambiguity when expression format is unclear. |
[ALLOWED_RANGE_TYPES] | Whitelist of acceptable range expression types to constrain parsing | ["explicit", "month", "quarter", "year"] | Optional. Must be valid JSON array of strings. Null means all types allowed. Reject output if canonicalized range type is not in whitelist. |
[CONFIDENCE_THRESHOLD] | Minimum confidence score required to accept the canonicalized output without human review | 0.85 | Optional. Float between 0.0 and 1.0. Default 0.8. Outputs below threshold should route to human review queue. |
Implementation Harness Notes
How to wire the date range parsing prompt into a reliable application workflow with validation, retries, and observability.
Integrating a date range parsing prompt into a production system requires more than a single API call. The prompt must be embedded in a harness that validates the output against a strict schema, handles malformed responses gracefully, and provides enough observability to debug failures. For a booking system or reporting pipeline, the canonical output—a start timestamp, end timestamp, and inclusivity flags—must be machine-readable and trustworthy before it reaches any downstream database or query engine. The harness should treat the LLM response as an untrusted input until it passes structural and semantic validation.
Start by defining the expected output schema in your application code, not just in the prompt. Require fields such as start_timestamp (ISO 8601), end_timestamp (ISO 8601), start_inclusive (boolean), end_inclusive (boolean), and a confidence score (0.0–1.0). After receiving the model response, validate that all required fields are present, types are correct, and timestamps parse without error. If validation fails, retry the prompt once with the original input and the validation error message appended as feedback. If the retry also fails, log the raw response, the input string, and the validation errors to an observability platform for later diagnosis. Do not silently fall back to a default date range—escalate to a human review queue or return a structured error to the caller.
For high-throughput pipelines, consider routing simpler, unambiguous inputs (like '2025-01-05 to 2025-01-12') through a deterministic parser before invoking the LLM. Reserve the prompt for genuinely ambiguous or natural-language expressions such as 'Q1 2024', 'next week', or 'the first half of March'. This reduces latency, cost, and failure surface. When you do call the model, prefer a fast, cost-effective option (like GPT-4o-mini or Claude Haiku) for this structured extraction task, and set a low temperature (0.0–0.1) to maximize output consistency. Log every request with a trace ID that ties the input string, model response, validation result, and any retries together for later analysis. Before shipping, run the harness against a golden dataset of overlapping, malformed, and edge-case range expressions to confirm that the validation and retry logic behaves correctly under real failure conditions.
Expected Output Contract
Define the canonical output shape for the date range parsing prompt. Use this contract to validate the model's response before it reaches downstream scheduling or reporting systems.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
start_timestamp | ISO 8601 string | Must parse as a valid UTC datetime. Must be chronologically before or equal to end_timestamp. | |
end_timestamp | ISO 8601 string | Must parse as a valid UTC datetime. Must be chronologically after or equal to start_timestamp. | |
start_inclusive | boolean | Must be true or false. If null, treat as true and flag a schema violation. | |
end_inclusive | boolean | Must be true or false. If null, treat as true and flag a schema violation. | |
original_input | string | Must exactly match the [RANGE_EXPRESSION] input string. Used for audit trail and debugging. | |
canonical_range | string | Must be a human-readable string confirming the resolved range, e.g., '2025-01-05T00:00:00Z to 2025-01-12T23:59:59Z (inclusive)'. | |
confidence | number | Must be a float between 0.0 and 1.0. Values below a configurable threshold (e.g., 0.8) should trigger a human review or retry. | |
repair_flags | array of strings | If present, must be an array of predefined flags such as 'ambiguous_year', 'missing_timezone', or 'inferred_end'. An empty array is allowed if no repair was needed. |
Common Failure Modes
Date range parsing fails in predictable ways. These cards cover the most common production failure modes and the guardrails that catch them before they corrupt downstream systems.
Ambiguous Range Boundaries
What to watch: Expressions like 'Jan 5-12' can mean inclusive of both endpoints, exclusive of the end, or inclusive of only the start. The model defaults to a single interpretation without signaling ambiguity. Guardrail: Require explicit inclusivity flags in the output schema (inclusive_start, inclusive_end as booleans) and test against a golden set of ambiguous ranges with known interpretations.
Missing Year Assumption Drift
What to watch: 'March 10-15' without a year causes the model to assume the current year, which silently breaks historical queries or future scheduling. The assumption changes as the system clock advances. Guardrail: Always require an explicit anchor_date input parameter and include the resolved year in the output. Log a warning when the input lacks a year component.
Quarter and Fiscal Period Misalignment
What to watch: 'Q1 2024' maps to calendar quarters by default, but many organizations use fiscal calendars with different boundaries. The model cannot know which convention applies. Guardrail: Require a fiscal_calendar configuration parameter (e.g., fiscal_year_start_month) and validate output boundaries against the configured calendar. Reject ranges that span fiscal year boundaries without explicit intent.
Reversed Start and End Dates
What to watch: 'December to January 2024' can be interpreted as Dec 2024–Jan 2024 (reversed) or Dec 2023–Jan 2024 (cross-year). The model may silently produce a range where start > end. Guardrail: Add a post-processing validation step that checks start <= end and rejects or flags reversed ranges. Include a cross_year_boundary boolean in the output to make the interpretation explicit.
Relative Range Drift Over Time
What to watch: 'Last week' or 'past 30 days' resolves relative to the current moment, making outputs non-reproducible and breaking audit trails. Re-running the same prompt later produces different results. Guardrail: Always capture and store the resolved_at timestamp alongside the output. For audit use cases, require an explicit reference_timestamp input instead of relying on system time.
Timezone Blindness in Range Endpoints
What to watch: A range like 'Jan 5, 2025' resolves to midnight in an unspecified timezone, causing off-by-one errors when the consuming system expects UTC or a specific locale. Guardrail: Require a timezone parameter (defaulting to UTC with an explicit log) and emit all timestamps with their IANA timezone identifier. Test boundary cases where the range endpoint falls on a DST transition.
Evaluation Rubric
Use this rubric to evaluate the quality of the Date Range Parsing and Canonicalization prompt before shipping. Each criterion targets a specific failure mode common in temporal range extraction.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Start/End Timestamp Accuracy | Start and end timestamps match the ground truth for the provided [DATE_RANGE_EXPRESSION] within a 1-second tolerance. | Output timestamps are off by more than 1 second, or the start/end are swapped. | Run against a golden dataset of 50 date range expressions with known ISO 8601 start/end pairs. Assert exact match or within-tolerance match. |
Inclusivity Flag Correctness | The | A flag is | Test with expressions like 'Jan 1 to Jan 31, 2025' (both inclusive) and 'Jan 1 until Jan 31, 2025' (end exclusive). Validate boolean fields. |
Ambiguous Range Resolution | For expressions like 'Q1 2024' or 'next week', the output matches the documented resolution rules (e.g., Q1 = Jan 1 - Mar 31). | Output uses a different interpretation than specified in [RESOLUTION_RULES], or returns null without a confidence score. | Feed 10 ambiguous expressions without anchor timestamps. Check that resolved ranges match the rulebook and include a non-null |
Malformed Input Handling | For unparseable inputs like 'the other day' or 'sometime next month', the output returns a null range and a | The model hallucinates a date range for an unparseable input, or returns a valid range without a low confidence flag. | Provide 10 malformed or vague expressions. Assert that |
Timezone and Anchor Timestamp Adherence | When an [ANCHOR_TIMESTAMP] is provided, relative expressions like 'last month' resolve relative to that anchor's timezone. | Output ignores the provided anchor timezone, or resolves relative to UTC when the anchor is in a different zone. | Test 'last month' with anchors in UTC, US/Eastern, and Asia/Tokyo. Assert that the resolved month boundaries match the anchor's zone. |
Overlapping Range Detection | When [INPUT] contains multiple date range expressions, the output includes an | Overlapping ranges are returned without any overlap flag, or the | Provide text with 'Jan 5-12 and Jan 10-15, 2025'. Assert that the |
Output Schema Compliance | The JSON output validates against the [OUTPUT_SCHEMA] with all required fields present and correctly typed. | Required fields like | Validate every output against the JSON Schema using a programmatic validator. Assert zero schema violations across 100 test cases. |
Confidence Score Calibration | The | Confidence is 1.0 for a vague expression like 'later this year', or 0.5 for a precise ISO 8601 interval. | Run 20 cases with known ambiguity levels. Assert that confidence correlates with ambiguity: Spearman rank correlation > 0.8 against human-labeled ambiguity scores. |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a simple JSON schema for the output. Use a single model call without retries. Accept [START_TIMESTAMP] and [END_TIMESTAMP] as ISO 8601 strings with [INCLUSIVITY_FLAGS] as booleans.
Watch for
- Ambiguous ranges like 'last week' resolving to different anchors
- Missing timezone assumptions when input lacks offset
- Model returning natural language instead of structured JSON

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us