{"record":{"id":"fe0868c48a778a37","repo":"vercel/ai","slug":"harness-pi-does-not-support-structured-output","errorCode":null,"errorMessage":"Harness 'pi' does not support structured output.","messagePattern":"Harness 'pi' does not support structured output\\.","errorType":"exception","errorClass":"HarnessCapabilityUnsupportedError","httpStatus":null,"severity":"error","filePath":"packages/harness-pi/src/pi-session.ts","lineNumber":1344,"sourceCode":"      type: 'resume-session',\n      harnessId: HARNESS_ID,\n      specificationVersion: 'harness-v1',\n      data: sessionFileName ? { sessionFileName } : {},\n    };\n  };\n\n  const sessionImpl: HarnessV1Session = {\n    sessionId: input.sessionId,\n    isResume: input.isResume,\n    // Pi has no bridge to attach to and no on-disk event log to replay; its\n    // only resume path is restoring the session file on a fresh/snapshotted\n    // sandbox, i.e. `rerun`.\n\n    doPromptTurn: async (\n      promptOpts: HarnessV1PromptTurnOptions,\n    ): Promise<HarnessV1PromptControl> => {\n      if (promptOpts.responseFormat?.type === 'json') {\n        throw new HarnessCapabilityUnsupportedError({\n          message: \"Harness 'pi' does not support structured output.\",\n          harnessId: HARNESS_ID,\n        });\n      }\n      return runTurn({\n        text: extractUserText(promptOpts.prompt),\n        ...(promptOpts.model ? { model: promptOpts.model } : {}),\n        skills: promptOpts.skills,\n        tools: promptOpts.tools ?? [],\n        instructions: promptOpts.instructions,\n        emit: promptOpts.emit,\n        abortSignal: promptOpts.abortSignal,\n      });\n    },\n\n    doContinueTurn: async (\n      continueOpts: HarnessV1ContinueTurnOptions,\n    ): Promise<HarnessV1PromptControl> => {","sourceCodeStart":1326,"sourceCodeEnd":1362,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness-pi/src/pi-session.ts#L1326-L1362","documentation":"The Pi harness is a coding-agent harness that produces free-form streamed output and cannot honor `responseFormat` of type 'json'. When a prompt turn requests structured output, the adapter throws HarnessCapabilityUnsupportedError, a typed capability error carrying the harness id.","triggerScenarios":"Calling prompt/doPromptTurn on a 'pi' harness session with `responseFormat: { type: 'json' }` (e.g. from generateObject/streamObject over a harness).","commonSituations":"Sharing a prompt pipeline between model providers and harnesses and hitting the pi harness with an object-generation request; assuming harnesses support the full language-model surface.","solutions":["Do not request json responseFormat against the pi harness; parse structured data from the agent's final text instead","Check harness capability metadata before issuing structured-output turns","Switch to a model/provider path (generateObject with a provider model) when structured output is required"],"exampleFix":"// before\nawait session.prompt({\n  prompt: 'extract entities',\n  responseFormat: { type: 'json' }, // unsupported on pi\n});\n// after\nconst result = await session.prompt({ prompt: 'extract entities as JSON' });\nconst data = JSON.parse(extractText(result));","handlingStrategy":"try-catch","validationCode":"export function supportsStructuredOutput(harnessId: string): boolean {\n  return harnessId !== 'pi';\n}\nif (opts.responseFormat?.type === 'json' && !supportsStructuredOutput(harnessId)) {\n  // route to a provider model or strip responseFormat\n}","typeGuard":"import { HarnessCapabilityUnsupportedError } from './harness-capability-unsupported-error';\nfunction isCapabilityUnsupported(e: unknown): e is HarnessCapabilityUnsupportedError {\n  return HarnessCapabilityUnsupportedError.isInstance(e);\n}","tryCatchPattern":"try {\n  return await session.prompt(opts);\n} catch (e) {\n  if (isCapabilityUnsupported(e)) {\n    return fallbackTextBasedExtraction(opts.prompt); // strip responseFormat\n  }\n  throw e;\n}","preventionTips":["Check harness capability metadata before enabling structured-output features","Keep separate code paths for model-provider structured output vs agent harness turns","Catch HarnessCapabilityUnsupportedError at the pipeline boundary and degrade gracefully"],"tags":["capability","structured-output","unsupported"],"backgroundTag":"capability-unsupported","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}