{"record":{"id":"dfb06f6b4f524be4","repo":"coleam00/Archon","slug":"node-node-id-failed-to-serialize-structured","errorCode":null,"errorMessage":"Node '${node.id}': failed to serialize structured_output to JSON: ${err.message}","messagePattern":"Node '(.+?)': failed to serialize structured_output to JSON: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/workflows/src/dag-executor.ts","lineNumber":3036,"sourceCode":"        );\n        if (schemaCompileError !== undefined) {\n          getLog().warn(\n            { nodeId: node.id, workflowRunId: workflowRun.id, compileMsg: schemaCompileError },\n            'dag.structured_output_schema_uncompilable'\n          );\n          await safeSendMessage(\n            platform,\n            conversationId,\n            `⚠️ Node '${node.id}': its \\`output_format\\` schema could not be compiled (${schemaCompileError}), so the structured output was NOT validated against it. Fix the schema to enforce it.`,\n            nodeContext\n          );\n        }\n        if (validation.valid) {\n          try {\n            nodeOutputText = canonicalValueText(structuredOutput);\n          } catch (serializeErr) {\n            const err = serializeErr as Error;\n            throw new Error(\n              `Node '${node.id}': failed to serialize structured_output to JSON: ${err.message}`\n            );\n          }\n          getLog().debug({ nodeId: node.id, streamingMode }, 'dag.structured_output_override');\n          break;\n        }\n        // Invalid payload.\n        getLog().warn(\n          { nodeId: node.id, workflowRunId: workflowRun.id, errors: validation.errors },\n          'dag.structured_output_invalid'\n        );\n        if (canReask) {\n          await scheduleReask(validation.errors);\n          continue;\n        }\n        throw new Error(\n          `Node '${node.id}': output_format declared but the provider's structured output failed schema validation: ${validation.errors.join('; ')}`\n        );","sourceCodeStart":3018,"sourceCodeEnd":3054,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/workflows/src/dag-executor.ts#L3018-L3054","documentation":"When a node declares output_format and the provider's structured output passes schema validation, the executor converts it to canonical JSON via canonicalValueText. If that serialization throws (e.g. non-JSON-serializable values like BigInt, circular structures), the node fails with this error wrapping the underlying message.","triggerScenarios":"structuredOutput validated against the schema but contains values canonicalValueText cannot serialize to JSON — typically unusual value types produced by a provider adapter or a schema allowing exotic types.","commonSituations":"A custom provider adapter returning non-standard JS values (BigInt, undefined-in-arrays, circular refs); a schema that validated loosely enough to admit unserializable data; bug in structured-output parsing.","solutions":["Inspect err.message in the error to see which value failed serialization.","Tighten the output_format schema so only JSON-serializable types are allowed (no exotic types).","Check/fix the provider adapter that produced the structured output value.","Report/fix a canonicalValueText bug if the value is ordinary JSON data."],"exampleFix":"// before\nschema allows: { id: \"integer-as-bigint\" }  // adapter yields BigInt\n// after\nschema: { id: { type: \"string\" } }  // or convert BigInt in adapter","handlingStrategy":"type-guard","validationCode":"function isJsonSerializable(v: unknown, seen = new Set()): boolean {\n  if (v === null || ['string','number','boolean'].includes(typeof v)) return true;\n  if (typeof v === 'bigint') return false;\n  if (typeof v !== 'object') return false;\n  if (seen.has(v)) return false;\n  seen.add(v);\n  return Object.values(v).every(x => isJsonSerializable(x, seen));\n}","typeGuard":"function isPlainJsonObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v) && Object.getPrototypeOf(v) === Object.prototype;\n}","tryCatchPattern":"try {\n  await runNode(node);\n} catch (e) {\n  if (String(e).includes('failed to serialize structured_output')) console.error('Non-JSON value in structured output — inspect adapter');\n  else throw e;\n}","preventionTips":["Restrict output_format schemas to plain JSON types.","Audit custom provider adapters for exotic value types.","Round-trip structured outputs through JSON.parse(JSON.stringify()) in adapters."],"tags":["serialization","json","structured-output"],"backgroundTag":"json-serialization-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}