mastra-ai/mastra · error

Location '${inputData.city}' not found

Error message

Location '${inputData.city}' not found

What it means

The weather tool queries the open-meteo geocoding API to convert the user-supplied city into latitude/longitude. If the API responds without a first result (results[0] undefined), the tool throws "Location '<city>' not found". This is an external-API lookup miss, not a code bug: the city string did not resolve in the geocoding service.

Source

Thrown at packages/agent-builder/src/defaults.ts:294

  id: 'fetch-weather',
  description: 'Fetches weather forecast for a given city',
  inputSchema: z.object({
    city: z.string().describe('The city to get the weather for'),
  }),
  outputSchema: forecastSchema,
  execute: async (inputData) => {
    if (!inputData) {
      throw new Error('Input data not found');
    }

    const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(inputData.city)}&count=1\`;
    const geocodingResponse = await fetch(geocodingUrl);
    const geocodingData = (await geocodingResponse.json()) as {
      results: { latitude: number; longitude: number; name: string }[];
    };

    if (!geocodingData.results?.[0]) {
      throw new Error(\`Location '\${inputData.city}' not found\`);
    }

    const { latitude, longitude, name } = geocodingData.results[0];

    const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}&current=precipitation,weathercode&timezone=auto,&hourly=precipitation_probability,temperature_2m\`
    const response = await fetch(weatherUrl);
    const data = (await response.json()) as {
      current: {
        time: string;
        precipitation: number;
        weathercode: number;
      };
      hourly: {
        precipitation_probability: number[];
        temperature_2m: number[];
      };
    };

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Retry with a correctly spelled, well-known city name (e.g. 'London', 'Paris')
  2. Normalize/validate the city string before passing it to the tool
  3. Check that the geocoding API is reachable (curl the search URL manually) and not returning an error body
  4. Handle the throw in the surrounding workflow/agent turn and ask the user for a valid location

Example fix

// before
const data = await mastra.getWorkflow('weatherWorkflow').start({ triggerData: { city: 'San Fransisco' } });

// after
const data = await mastra.getWorkflow('weatherWorkflow').start({ triggerData: { city: 'San Francisco' } });
Defensive patterns

Strategy: try-catch

Validate before calling

const url = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(city)}&count=1`;
const preview = await fetch(url).then(r => r.json());
if (!preview?.results?.length) throw new Error(`'${city}' is not geocodable; pick a known city`);

Try / catch

try {
  await mastra.getWorkflow('weatherWorkflow').start({ triggerData: { city } });
} catch (e) {
  if (e instanceof Error && e.message.includes('not found')) {
    // prompt user for a valid city
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the default weather workflow/tool with a city that open-meteo's geocoding API cannot resolve — misspelled names, non-city strings, cities in unsupported scripts, or empty results from https://geocoding-api.open-meteo.com/v1/search.

Common situations: Test agents asking for fictional places ('Atlantis', 'My House'); typos like 'San Fransisco'; user input in a language/script geocoding doesn't index; network degradation returning a non-error JSON body without results.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/606f9cfcca9fdb52. Report an issue: GitHub.