fix(workflow-utils): llmExtract dryRun returns schema-shaped defaults #126

Merged
xiaomo merged 1 commits from fix/123-llmextract-dryrun-defaults into main 2026-04-25 04:35:45 +00:00
Owner

What

Replace ok({} as T) with ok(schemaDefaults(options.schema) as T) in llmExtract's dryRun path.

Why

Empty object causes downstream crashes (Cannot read properties of undefined (reading 'map')) in any workflow that accesses extracted fields. Every workflow had to add its own dryRun guard — not scalable.

Changes

  • packages/workflow-utils/src/schema-defaults.ts — new schemaDefaults(schema) helper that generates structurally valid defaults from zod schemas (string→"", number→0, array→[], object→recurse, enum→first value, etc.)
  • packages/workflow-utils/src/llm-extract.ts — dryRun path uses schemaDefaults
  • packages/workflow-utils/src/index.ts — re-export schemaDefaults
  • packages/workflow-utils/src/__tests__/schema-defaults.test.ts — 5 tests covering nested objects, arrays, enums, optionals
  • packages/workflow-utils/src/__tests__/llm-extract.test.ts — updated dryRun assertion

Ref

Fixes #123

## What Replace `ok({} as T)` with `ok(schemaDefaults(options.schema) as T)` in llmExtract's dryRun path. ## Why Empty object causes downstream crashes (`Cannot read properties of undefined (reading 'map')`) in any workflow that accesses extracted fields. Every workflow had to add its own dryRun guard — not scalable. ## Changes - **`packages/workflow-utils/src/schema-defaults.ts`** — new `schemaDefaults(schema)` helper that generates structurally valid defaults from zod schemas (string→"", number→0, array→[], object→recurse, enum→first value, etc.) - **`packages/workflow-utils/src/llm-extract.ts`** — dryRun path uses `schemaDefaults` - **`packages/workflow-utils/src/index.ts`** — re-export `schemaDefaults` - **`packages/workflow-utils/src/__tests__/schema-defaults.test.ts`** — 5 tests covering nested objects, arrays, enums, optionals - **`packages/workflow-utils/src/__tests__/llm-extract.test.ts`** — updated dryRun assertion ## Ref Fixes #123
xiaoju added 1 commit 2026-04-25 04:33:41 +00:00
Add schemaDefaults() from Zod def types; export from package; tests for nested/array/enum/optional.

Made-with: Cursor
xiaomo approved these changes 2026-04-25 04:35:44 +00:00
xiaomo left a comment
Owner

LGTM

schemaDefaults 实现扎实,覆盖 zod 所有主要类型,optional vs exactOptional 区分处理得当,.default() 正确支持。测试覆盖关键边界。llmExtract 一行改动精准解决 dryRun 下游 crash。

LGTM schemaDefaults 实现扎实,覆盖 zod 所有主要类型,optional vs exactOptional 区分处理得当,.default() 正确支持。测试覆盖关键边界。llmExtract 一行改动精准解决 dryRun 下游 crash。
xiaomo merged commit ce20d73ab6 into main 2026-04-25 04:35:45 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#126