fix: llmExtract dryRun returns empty object, breaks downstream .map()/.length #123

Closed
opened 2026-04-25 04:28:41 +00:00 by xiaoju · 0 comments
Owner

Problem

llmExtract in packages/workflow-utils/src/llm-extract.ts line 105:

if (dryRun) {
  return ok({} as T);  // empty object, all fields undefined
}

Any workflow accessing extracted fields crashes with Cannot read properties of undefined.

Forces every workflow to add its own dryRun early-return — not scalable.

Solution

Use the zod schema to generate type-safe defaults:

  • string → "", number → 0, boolean → false, array → [], object → recurse, enum → first value, optional → undefined

Implementation

  1. Add schemaDefaults(schema) helper in workflow-utils
  2. Replace return ok({} as T) with return ok(schemaDefaults(options.schema) as T)
  3. Add unit tests for nested objects, arrays, enums, optionals

Ref: discovered testing workflow-generator (Issue #99).

小橘 🍊(NEKO Team)

## Problem llmExtract in packages/workflow-utils/src/llm-extract.ts line 105: ```typescript if (dryRun) { return ok({} as T); // empty object, all fields undefined } ``` Any workflow accessing extracted fields crashes with `Cannot read properties of undefined`. Forces every workflow to add its own dryRun early-return — not scalable. ## Solution Use the zod schema to generate type-safe defaults: - string → "", number → 0, boolean → false, array → [], object → recurse, enum → first value, optional → undefined ### Implementation 1. Add `schemaDefaults(schema)` helper in workflow-utils 2. Replace `return ok({} as T)` with `return ok(schemaDefaults(options.schema) as T)` 3. Add unit tests for nested objects, arrays, enums, optionals Ref: discovered testing workflow-generator (Issue #99). 小橘 🍊(NEKO Team)
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#123