Mintplex-Labs/anything-llm · error

Invalid period: " ". Use "today", "tomorrow", "week", "this…

Error message

Invalid period: "${period}". Use "today", "tomorrow", "week", "this week", "next week", "month", "this month", or "next month".

What it means

Thrown by the default branch of the period switch in GCalGetUpcomingEvents when the period argument is not one of the eight supported strings: today, tomorrow, week, this week, next week, month, this month, next month. The message enumerates the allowed values, so the fix is always to normalize the caller's input to that vocabulary. It is plain enum validation on an LLM-supplied tool argument.

Solutions

  1. Map free-form input to the closest supported value before invoking the tool (e.g. 'this weekend' -> 'week', 'next 30 days' -> 'next month').
  2. Constrain the agent with a tool schema/enum listing exactly the eight strings so the model cannot emit anything else.
  3. Default to 'this week' when input is unrecognized instead of letting the error propagate to the agent turn.

Example fix

// before
gcal_get_upcoming_events({ period: "this weekend" })  // throws

// after
const SUPPORTED = ["today","tomorrow","week","this week","next week","month","this month","next month"];
const period = SUPPORTED.includes(input) ? input : "this week";
gcal_get_upcoming_events({ period });
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_PERIODS = ["today", "tomorrow", "week", "this week", "next week", "month", "this month", "next month"];
function normalizePeriod(input) {
  const p = String(input ?? "").trim().toLowerCase();
  return SUPPORTED_PERIODS.includes(p) ? p : "this week"; // safe default instead of throw
}

Type guard

/** @param {unknown} v @returns {boolean} */
function isSupportedPeriod(v) {
  return typeof v === "string" && SUPPORTED_PERIODS.includes(v.trim().toLowerCase());
}

Try / catch

try {
  const range = getCalendarDuration(period);
} catch (e) {
  if (e.message.startsWith("Invalid period:")) {
    range = getCalendarDuration("this week"); // fall back to a supported bucket
  } else throw e;
}

Prevention

When it happens

Trigger: Agent passes 'this weekend', 'next 7 days', 'year', 'this quarter', or an empty string as period; user phrasing is copied verbatim instead of mapped to a supported bucket; a locale difference (' Cette semaine') reaches the tool unmapped.

Common situations: LLM free-forming the period instead of using the enum; prompt updates that rename the parameter vocabulary; multi-word variants like 'the week' slipping through a thin wrapper.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/d28bd8fc762915a2. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/agents/aibitat/plugins/google-calendar/events/gcal-get-upcoming-events.js:66

    case "this month":
      startDate = new Date(today);
      endDate = new Date(today);
      endDate.setDate(endDate.getDate() + 30);
      endDate.setHours(23, 59, 59, 999);
      label = "the next 30 days";
      break;

    case "next month":
      startDate = new Date(today);
      startDate.setDate(startDate.getDate() + 30);
      endDate = new Date(startDate);
      endDate.setDate(endDate.getDate() + 30);
      endDate.setHours(23, 59, 59, 999);
      label = "next month";
      break;

    default:
      throw new Error(
        `Invalid period: "${period}". Use "today", "tomorrow", "week", "this week", "next week", "month", "this month", or "next month".`
      );
  }

  return {
    startDate: startDate.toISOString(),
    endDate: endDate.toISOString(),
    label,
  };
}

module.exports.GCalGetUpcomingEvents = {
  name: "gcal-get-upcoming-events",
  plugin: function () {
    return {
      name: "gcal-get-upcoming-events",
      setup(aibitat) {
        aibitat.function({

View on GitHub (pinned to 3aec848f28)