{"record":{"id":"5062abe741750091","repo":"vercel/ai","slug":"moonshot-ai-partial-mode-cannot-be-combined-with-j","errorCode":null,"errorMessage":"Moonshot AI Partial Mode cannot be combined with JSON object response format.","messagePattern":"Moonshot AI Partial Mode cannot be combined with JSON object response format\\.","errorType":"validation","errorClass":"InvalidPromptError","httpStatus":null,"severity":"error","filePath":"packages/moonshotai/src/convert-to-moonshotai-chat-messages.ts","lineNumber":303,"sourceCode":"            name: moonshotMessageOptions.name,\n          }),\n        });\n\n        break;\n      }\n\n      case 'assistant': {\n        if (moonshotMessageOptions?.partial === true) {\n          if (index !== prompt.length - 1) {\n            throw new InvalidPromptError({\n              prompt,\n              message:\n                'Moonshot AI Partial Mode requires the partial assistant message to be the final message.',\n            });\n          }\n\n          if (responseFormat?.type === 'json_object') {\n            throw new InvalidPromptError({\n              prompt,\n              message:\n                'Moonshot AI Partial Mode cannot be combined with JSON object response format.',\n            });\n          }\n        }\n\n        let text = '';\n        let reasoning = '';\n        const toolCalls: Array<{\n          id: string;\n          type: 'function';\n          function: { name: string; arguments: string };\n        }> = [];\n\n        for (const part of content) {\n          switch (part.type) {\n            case 'text': {","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/moonshotai/src/convert-to-moonshotai-chat-messages.ts#L285-L321","documentation":"Moonshot AI Partial Mode (an incomplete assistant prefix message) is incompatible with a 'json_object' response format: the API cannot both continue a partial message and force JSON output. The converter throws InvalidPromptError when both are requested in the same call.","triggerScenarios":"Calling generateText/streamObject with responseFormat type 'json_object' while an assistant message in the prompt has providerOptions.moonshot.partial = true.","commonSituations":"Combining a continue-completion feature with structured JSON output; copying provider options between calls and leaving partial: true set when switching to generateObject.","solutions":["Remove partial: true from the assistant message when using JSON object response format.","Drop the json_object response format if continuation of the partial message is what you need.","If you need JSON from a continuation, post-process the continued text with a schema parser instead.","Split into two calls: one to complete the partial message, then one with json_object."],"exampleFix":"// before\n{ responseFormat: { type: 'json_object' }, messages: [assistant('...', { partial: true })] }\n// after\n{ messages: [assistant('...')] } // or remove responseFormat","handlingStrategy":"validation","validationCode":"function partialModeWithJson(messages: ModelMessage[], responseFormat?: { type: string }): boolean {\n  const hasPartial = messages.some(m => m.role === 'assistant' && (m.providerOptions?.moonshot as any)?.partial === true);\n  return hasPartial && responseFormat?.type === 'json_object';\n}\nif (partialModeWithJson(messages, responseFormat)) throw new Error('Partial Mode cannot be combined with json_object');","typeGuard":null,"tryCatchPattern":"import { InvalidPromptError } from '@ai-sdk/provider';\ntry {\n  await generateText({ model: moonshot(id), messages, /* responseFormat */ });\n} catch (e) {\n  if (InvalidPromptError.isInstance(e) && e.message.includes('cannot be combined')) {\n    // retry without partial: true or without json_object\n  }\n  throw e;\n}","preventionTips":["Treat partial: true and json_object response format as mutually exclusive options.","Reset providerOptions.moonshot.partial when switching between continuation and structured-output calls.","Centralize Moonshot call configuration so the two flags cannot be set together.","Parse continued text into JSON with a schema validator instead of using json_mode during continuation."],"tags":["moonshotai","invalid-prompt","partial-mode","response-format","json-mode"],"backgroundTag":"incompatible-options-combination","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}