fix(workflow-utils): llmExtract dryRun returns schema-shaped defaults #126
Reference in New Issue
Block a user
Delete Branch "fix/123-llmextract-dryrun-defaults"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Replace
ok({} as T)withok(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— newschemaDefaults(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 usesschemaDefaultspackages/workflow-utils/src/index.ts— re-exportschemaDefaultspackages/workflow-utils/src/__tests__/schema-defaults.test.ts— 5 tests covering nested objects, arrays, enums, optionalspackages/workflow-utils/src/__tests__/llm-extract.test.ts— updated dryRun assertionRef
Fixes #123
LGTM
schemaDefaults 实现扎实,覆盖 zod 所有主要类型,optional vs exactOptional 区分处理得当,.default() 正确支持。测试覆盖关键边界。llmExtract 一行改动精准解决 dryRun 下游 crash。
xiaoju referenced this pull request2026-04-25 04:41:39 +00:00