mastra-ai/mastra · error · HTTPException

Stored prompt block with id ${storedPromptBlockId} not found

Error message

Stored prompt block with id ${storedPromptBlockId} not found

What it means

HTTP 404 thrown when promptBlockStore.getByIdResolved(id, { status }) finds no stored prompt block with the given id. The id is path-valid but no record matches in the configured storage, or it is not visible in the requested status/scope.

Source

Thrown at packages/server/src/server/handlers/stored-prompt-blocks.ts:125

  tags: ['Stored Prompt Blocks'],
  requiresAuth: true,
  handler: async ({ mastra, storedPromptBlockId, status, requestContext }) => {
    try {
      const storage = mastra.getStorage();

      if (!storage) {
        throw new HTTPException(500, { message: 'Storage is not configured' });
      }

      const promptBlockStore = await storage.getStore('promptBlocks');
      if (!promptBlockStore) {
        throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });
      }

      const promptBlock = await promptBlockStore.getByIdResolved(storedPromptBlockId, { status });

      if (!promptBlock) {
        throw new HTTPException(404, { message: `Stored prompt block with id ${storedPromptBlockId} not found` });
      }
      assertStoredResourceScope(promptBlock, await getStoredResourceScope(mastra, requestContext));

      const latestVersion = await promptBlockStore.getLatestVersion(storedPromptBlockId);

      return { ...promptBlock, hasDraft: computeHasDraft(latestVersion, promptBlock.activeVersionId) };
    } catch (error) {
      return handleError(error, 'Error getting stored prompt block');
    }
  },
});

/**
 * POST /stored/prompt-blocks - Create a new stored prompt block
 */
export const CREATE_STORED_PROMPT_BLOCK_ROUTE = createRoute({
  method: 'POST',
  path: '/stored/prompt-blocks',

View on GitHub (pinned to 75dd419e61)

Solutions

  1. List prompt blocks to confirm the id exists and copy it from the response
  2. Drop or correct the status query parameter so the default resolution applies
  3. Verify you are querying the environment/database that contains the block
  4. Check resource scope — the block may exist but be hidden from your request context
Defensive patterns

Strategy: try-catch

Validate before calling

const store = await mastra.getStorage()?.getStore('promptBlocks');
const list = await store?.listResolved({ page: 0, perPage: 100 });
if (!list?.results.some(b => b.id === id)) throw new Error(`prompt block ${id} not found`);

Try / catch

try {
  const block = await client.getStoredPromptBlock(id, { status });
} catch (e) {
  if (isHttpError(e, 404)) {
    // refresh id from list endpoint; check status filter and scope
  }
}

Prevention

When it happens

Trigger: GET /api/stored-prompt-blocks/:id where the id doesn't exist, was deleted, exists only under a different status than requested, or is outside the caller's stored-resource scope.

Common situations: Stale bookmarked id after a database reset; id copied from another environment; requesting status 'draft' when only 'active' exists; multi-tenant scope mismatch.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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