{"record":{"id":"e3d3099c3c12d49d","repo":"mastra-ai/mastra","slug":"mastra-get-prompt-block-not-found","errorCode":"MASTRA_GET_PROMPT_BLOCK_NOT_FOUND","errorMessage":"Prompt block with key ${key} not found","messagePattern":"Prompt block with key (.+?) not found","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/mastra/index.ts","lineNumber":4126,"sourceCode":"   * @param key - Optional registration key (defaults to promptBlock.id)\n   */\n  public addPromptBlock(promptBlock: StorageResolvedPromptBlockType, key?: string): void {\n    const blockKey = key || promptBlock.id;\n    if (this.#promptBlocks[blockKey]) {\n      return;\n    }\n    this.#promptBlocks[blockKey] = promptBlock;\n  }\n\n  /**\n   * Retrieves a registered prompt block by its key.\n   *\n   * @throws {MastraError} When the prompt block with the specified key is not found\n   */\n  public getPromptBlock(key: string): StorageResolvedPromptBlockType {\n    const block = this.#promptBlocks[key];\n    if (!block) {\n      throw new MastraError({\n        id: 'MASTRA_GET_PROMPT_BLOCK_NOT_FOUND',\n        domain: ErrorDomain.MASTRA,\n        category: ErrorCategory.USER,\n        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;","sourceCodeStart":4108,"sourceCodeEnd":4144,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/mastra/index.ts#L4108-L4144","documentation":"Mastra.getPromptBlock(key) looks up a registered prompt block by its key in the internal #promptBlocks map. If no block was registered under that exact key, Mastra throws this MastraError (ErrorCategory.USER) because the caller referenced a block that does not exist. It is a lookup failure on user-supplied input, not an internal fault.","triggerScenarios":"Calling mastra.getPromptBlock('myKey') where 'myKey' was never passed when registering prompt blocks (or was registered under a different key, or with different casing/whitespace).","commonSituations":"Typo in the key string; key renamed during a refactor; reading the key from config/env where it is empty or stale; registering blocks conditionally so the block is absent in some environments.","solutions":["List the registered prompt blocks (e.g. via the corresponding list/get-all accessor) and confirm the exact key, then use that key verbatim.","Fix typos or casing so the key matches the registration exactly (keys are matched with strict equality).","Register the missing block via registerPromptBlock (or the Mastra constructor config) before calling getPromptBlock.","If the key is user/config supplied, validate it against the known keys before lookup."],"exampleFix":"// before\nconst block = mastra.getPromptBlock('system-instructions');\n// after (check the actual registered key)\nconst blocks = mastra.getPromptBlocks();\nconsole.log(Object.keys(blocks)); // e.g. ['systemInstructions']\nconst block = mastra.getPromptBlock('systemInstructions');","handlingStrategy":"validation","validationCode":"const blocks = mastra.getPromptBlocks?.() ?? {};\nif (!(key in blocks)) {\n  throw new Error(`Prompt block key \"${key}\" is not registered. Available: ${Object.keys(blocks).join(', ')}`);\n}\nconst block = mastra.getPromptBlock(key);","typeGuard":null,"tryCatchPattern":"try {\n  const block = mastra.getPromptBlock(key);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'MASTRA_GET_PROMPT_BLOCK_NOT_FOUND') {\n    // fall back to a default block or skip the block injection\n  } else throw e;\n}","preventionTips":["Keep prompt block keys as exported constants instead of inline strings.","Before lookup, list registered blocks and fail early with the available keys.","Add a startup check that every key referenced in config exists in the registry."],"tags":["lookup-failed","prompt-block","user-input"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}