coleam00/Archon · error

Node ' ': failed to serialize structured_output to JSON

Error message

Node '${node.id}': failed to serialize structured_output to JSON: ${err.message}

What it means

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.

Solutions

  1. Inspect err.message in the error to see which value failed serialization.
  2. Tighten the output_format schema so only JSON-serializable types are allowed (no exotic types).
  3. Check/fix the provider adapter that produced the structured output value.
  4. Report/fix a canonicalValueText bug if the value is ordinary JSON data.

Example fix

// before
schema allows: { id: "integer-as-bigint" }  // adapter yields BigInt
// after
schema: { id: { type: "string" } }  // or convert BigInt in adapter
Defensive patterns

Strategy: type-guard

Validate before calling

function isJsonSerializable(v: unknown, seen = new Set()): boolean {
  if (v === null || ['string','number','boolean'].includes(typeof v)) return true;
  if (typeof v === 'bigint') return false;
  if (typeof v !== 'object') return false;
  if (seen.has(v)) return false;
  seen.add(v);
  return Object.values(v).every(x => isJsonSerializable(x, seen));
}

Type guard

function isPlainJsonObject(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null && !Array.isArray(v) && Object.getPrototypeOf(v) === Object.prototype;
}

Try / catch

try {
  await runNode(node);
} catch (e) {
  if (String(e).includes('failed to serialize structured_output')) console.error('Non-JSON value in structured output — inspect adapter');
  else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of coleam00/Archon@0773b97458 (2026-09-01). Data as JSON: /api/errors/dfb06f6b4f524be4. Report an issue: GitHub.

Appendix: source

Thrown at packages/workflows/src/dag-executor.ts:3036

        );
        if (schemaCompileError !== undefined) {
          getLog().warn(
            { nodeId: node.id, workflowRunId: workflowRun.id, compileMsg: schemaCompileError },
            'dag.structured_output_schema_uncompilable'
          );
          await safeSendMessage(
            platform,
            conversationId,
            `⚠️ 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.`,
            nodeContext
          );
        }
        if (validation.valid) {
          try {
            nodeOutputText = canonicalValueText(structuredOutput);
          } catch (serializeErr) {
            const err = serializeErr as Error;
            throw new Error(
              `Node '${node.id}': failed to serialize structured_output to JSON: ${err.message}`
            );
          }
          getLog().debug({ nodeId: node.id, streamingMode }, 'dag.structured_output_override');
          break;
        }
        // Invalid payload.
        getLog().warn(
          { nodeId: node.id, workflowRunId: workflowRun.id, errors: validation.errors },
          'dag.structured_output_invalid'
        );
        if (canReask) {
          await scheduleReask(validation.errors);
          continue;
        }
        throw new Error(
          `Node '${node.id}': output_format declared but the provider's structured output failed schema validation: ${validation.errors.join('; ')}`
        );

View on GitHub (pinned to 0773b97458)