{"record":{"id":"2dd96c8d4dc28655","repo":"mastra-ai/mastra","slug":"mastra-get-prompt-block-by-id-not-found","errorCode":"MASTRA_GET_PROMPT_BLOCK_BY_ID_NOT_FOUND","errorMessage":"Prompt block with id ${id} not found","messagePattern":"Prompt block with id (.+?) not found","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/mastra/index.ts","lineNumber":4148,"sourceCode":"        text: `Prompt block with key ${key} not found`,\n      });\n    }\n    return block;\n  }\n\n  /**\n   * Retrieves a registered prompt block by its ID.\n   *\n   * @throws {MastraError} When no prompt block is found with the specified ID\n   */\n  public getPromptBlockById(id: string): StorageResolvedPromptBlockType {\n    for (const [, block] of Object.entries(this.#promptBlocks)) {\n      if (block.id === id) {\n        return block;\n      }\n    }\n\n    throw new MastraError({\n      id: 'MASTRA_GET_PROMPT_BLOCK_BY_ID_NOT_FOUND',\n      domain: ErrorDomain.MASTRA,\n      category: ErrorCategory.USER,\n      text: `Prompt block with id ${id} not found`,\n    });\n  }\n\n  /**\n   * Removes a prompt block from the Mastra instance by its key or ID.\n   *\n   * @param keyOrId - The prompt block key or ID to remove\n   * @returns true if a prompt block was removed, false if not found\n   */\n  public removePromptBlock(keyOrId: string): boolean {\n    if (this.#promptBlocks[keyOrId]) {\n      delete this.#promptBlocks[keyOrId];\n      return true;\n    }","sourceCodeStart":4130,"sourceCodeEnd":4166,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/mastra/index.ts#L4130-L4166","documentation":"getPromptBlockById(id) iterates all registered prompt blocks and returns the first whose id matches. When no block has that id, Mastra throws this MastraError. Note this searches by the block's own id property, which is distinct from the registration key used by getPromptBlock.","triggerScenarios":"Calling mastra.getPromptBlockById('abc-123') where no registered prompt block's block.id equals 'abc-123'; passing a key where an id is expected (or vice versa); the block was never registered.","commonSituations":"Confusing the registration key with the block id; stale id after blocks were regenerated; integration/agent config referencing a block from another Mastra instance.","solutions":["Enumerate the registered prompt blocks and verify each block's id, then pass the exact id.","If you actually know the registration key, use getPromptBlock(key) instead of the id-based lookup.","Register the block with the expected id, or update the caller/config to use the id that was actually assigned.","Validate that the id exists in the collection before calling the getter."],"exampleFix":"// before\nconst block = mastra.getPromptBlockById('block-1'); // never registered with this id\n// after\nconst block = mastra.getPromptBlockById('kb-summary-v2'); // matches block.id === 'kb-summary-v2'","handlingStrategy":"validation","validationCode":"const blocks = mastra.getPromptBlocks?.() ?? {};\nconst exists = Object.values(blocks).some(b => b.id === id);\nif (!exists) throw new Error(`No prompt block with id \"${id}\" registered`);","typeGuard":null,"tryCatchPattern":"try {\n  const block = mastra.getPromptBlockById(id);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'MASTRA_GET_PROMPT_BLOCK_BY_ID_NOT_FOUND') {\n    return null; // treat as absent, don't crash the caller\n  } throw e;\n}","preventionTips":["Don't confuse registration keys with block ids; pick one lookup style per codebase.","Version block ids deliberately and keep a registry constant listing current ids.","Validate referenced block ids at app startup."],"tags":["lookup-failed","prompt-block","id-mismatch"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}