infiniflow/ragflow · error · ValueError

Querit time_range must use dN, wN, mN, yN, or YYYY-MM-DDtoYY

Error message

Querit time_range must use dN, wN, mN, yN, or YYYY-MM-DDtoYYYY-MM-DD.

What it means

The Querit agent tool validates its time_range parameter against TIME_RANGE_PATTERN = ^([dwmy][1-9][0-9]*|\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2})$ in _validate_search_inputs (agent/tools/querit.py:411). Any non-empty string that does not exactly match 'dN'/'wN'/'mN'/'yN' (N >= 1, no leading zero) or a literal 'YYYY-MM-DDtoYYYY-MM-DD' range raises ValueError before any API call is made. An empty string is allowed and means 'no time restriction'.

Source

Thrown at agent/tools/querit.py:412


def _validate_search_inputs(
    count: Any,
    chunks_per_doc: Any,
    time_range: Any,
    site_include: Any,
    site_exclude: Any,
    country_include: Any,
    language_include: Any,
) -> None:
    if type(count) is not int or count < 1:
        raise ValueError("Querit count must be an integer greater than or equal to 1.")
    if chunks_per_doc is not None and (type(chunks_per_doc) is not int or not 1 <= chunks_per_doc <= 3):
        raise ValueError("Querit chunks_per_doc must be an integer from 1 to 3.")
    if type(time_range) is not str:
        raise ValueError("Querit time_range must be a string.")
    if time_range and not TIME_RANGE_PATTERN.fullmatch(time_range):
        raise ValueError("Querit time_range must use dN, wN, mN, yN, or YYYY-MM-DDtoYYYY-MM-DD.")
    for name, value in (
        ("site_include", site_include),
        ("site_exclude", site_exclude),
        ("country_include", country_include),
        ("language_include", language_include),
    ):
        if not isinstance(value, list) or any(not isinstance(item, str) for item in value):
            raise ValueError(f"Querit {name} must be an array of strings.")


def _safe_error_message(error: Exception, api_key: str) -> str:
    message = str(error) or error.__class__.__name__
    return message.replace(api_key, "[REDACTED]") if api_key else message


def _querit_text(value: Any) -> str:
    return "" if value is None else str(value)

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Use the relative form: one letter d/w/m/y immediately followed by an integer >= 1 with no leading zero (e.g. 'd7', 'w4', 'm12', 'y1').
  2. Or use the absolute form with no spaces: '2024-01-01to2024-12-31' (ISO dates joined by the literal 'to').
  3. Pass an empty string (or omit the parameter) if you want no time filter.
  4. If you keep failing, test your value against the exact regex: re.fullmatch(r'([dwmy][1-9][0-9]*|\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2})', value).

Example fix

// before (canvas / tool params)
"time_range": "last 7 days"

// after
"time_range": "d7"
Defensive patterns

Strategy: validation

Validate before calling

import re
TIME_RANGE = re.compile(r"([dwmy][1-9][0-9]*|\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2})")

def valid_time_range(v):
    return isinstance(v, str) and (v == "" or TIME_RANGE.fullmatch(v))

Type guard

def is_querit_time_range(value) -> bool:
    if not isinstance(value, str):
        return False
    return value == "" or bool(re.fullmatch(r"[dwmy][1-9][0-9]*|\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2}", value))

Try / catch

try:
    querit.run(time_range=tr)
except ValueError as e:
    if "time_range" in str(e):
        tr = ""  # fall back to no restriction
        querit.run(time_range=tr)

Prevention

When it happens

Trigger: Calling the Querit component with time_range set to values like 'last 7 days', '7d' (prefix must come first), 'w0' or 'm' (N must be >= 1), '2024/01/01to2024/12/31' (slashes instead of dashes), '2024-01-01 to 2024-12-31' (spaces), or 'd7 ' (trailing whitespace defeats fullmatch). LLM-generated tool arguments that paraphrase the range instead of using the DSL are the most common producer.

Common situations: Users copy human-readable ranges from other search tools; day-first date formats; an LLM agent component fills time_range free-form; leading-zero counts like 'd07'.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/d123c114a84647cc. Report an issue: GitHub.