❌output-error-zod-import
- プラグイン
- outputai
- ソース
- GitHub で見る ↗
説明
Zod スキーマのインポートに関する問題を、Output SDK ワークフロー内で修正します。 次のような場合に使用: - 「incompatible schema」エラーが発生している - ステップの境界で型エラーが発生している - スキーマのバリデーションが失敗している - ステップ間でスキーマが一致しない
原文を表示
Fix Zod schema import issues in Output SDK workflows. Use when seeing "incompatible schema" errors, type errors at step boundaries, schema validation failures, or when schemas don't match between steps.
ユースケース
- ✓incompatible schemaエラーが発生しているとき
- ✓ステップの境界で型エラーが発生しているとき
- ✓スキーマのバリデーションが失敗しているとき
- ✓ステップ間でスキーマが一致しないとき
本文(日本語訳)
Zodインポート元の問題を修正する
概要
このスキルは、Zodスキーマを誤ったソースからインポートしている場合に、その問題を診断・修正するためのものです。
Output SDKでは、スキーマを zod から直接インポートするのではなく、@outputai/core からインポートする必要があります。
次のような場合に使用
"incompatible schema"エラーが発生している- ステップの境界で型エラーが発生している
- ステップ間でデータを受け渡す際にスキーマのバリデーションが失敗する
- Zodの型が一致しないという内容のエラーが表示される
"Expected ZodObject but received..."エラーが表示される
根本原因
この問題は、@outputai/core ではなく zod から z をインポートした場合に発生します。
どちらもZodスキーマを提供しますが、Output SDKのコンテキスト内では互換性のない異なるスキーマインスタンスが生成されます。
なぜ問題になるか: Output SDKは、シリアライゼーションとバリデーションのために特定バージョンのZodを内部で使用しています。 異なるZodインスタンスを使用した場合、同じ形状を定義していても、スキーマは技術的に異なるオブジェクトとして扱われます。
症状
エラーメッセージ
Error: Incompatible schema types
Error: Schema validation failed: expected compatible Zod instance
TypeError: Cannot read property 'parse' of undefined
問題を引き起こすコードパターン
// NG: 'zod' から直接インポートしている
import { z } from 'zod';
const inputSchema = z.object( {
name: z.string()
} );
解決策
ステップ1: すべてのZodインポートを検索する
コードベース内の誤ったインポートを検索します。
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
ステップ2: インポートを修正する
すべてのインポートを以下のように変更します。
// NG
import { z } from 'zod';
↓
// OK
import { z } from '@outputai/core';
ステップ3: zodへの直接依存がないか確認する
意図せずzodを他の箇所でインポートしていないか確認します。
grep -r "import.*zod" src/
すべての一致箇所が zod ではなく @outputai/core を示していることを確認してください。
修正前後の比較例
修正前(NG)
// src/workflows/my-workflow/steps/process.ts
import { z } from 'zod'; // NG!
import { step } from '@outputai/core';
export const processStep = step( {
name: 'processData',
inputSchema: z.object( {
id: z.string()
} ),
outputSchema: z.object( {
result: z.string()
} ),
fn: async input => {
return { result: `Processed ${input.id}` };
}
} );
修正後(OK)
// src/workflows/my-workflow/steps/process.ts
import { z, step } from '@outputai/core'; // OK!
export const processStep = step( {
name: 'processData',
inputSchema: z.object( {
id: z.string()
} ),
outputSchema: z.object( {
result: z.string()
} ),
fn: async input => {
return { result: `Processed ${input.id}` };
}
} );
検証手順
1. 残存する誤ったインポートを確認する
# 結果が返らないことを確認
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
2. プロジェクトをビルドする
npm run output:worker:build
3. ワークフローを実行する
npx output workflow run <workflowName> '<input>'
予防策
ESLintルール(ESLintを使用している場合)
zodの直接インポートを禁止するルールを追加します。
// .eslintrc.js
module.exports = {
rules: {
'no-restricted-imports': [ 'error', {
paths: [ {
name: 'zod',
message: "Import { z } from '@outputai/core' instead of 'zod'"
} ]
} ]
}
};
IDEの設定
エディタが @outputai/core から自動インポートするよう設定します。
VS Codeの場合、settings.json に以下を追加します。
{
"typescript.preferences.autoImportFileExcludePatterns": ["zod"]
}
よくある落とし穴
同一ファイル内でのインポートの混在
誤ったインポートが1つでもあれば問題が発生します。
import { z } from '@outputai/core';
import { z as zod } from 'zod'; // これが問題を引き起こす!
間接的な依存関係
ユーティリティファイルで誤ったインポートが使われており、そのファイルが共有されている場合:
// utils/schemas.ts
import { z } from 'zod'; // NG!このスキーマを使っているすべてのファイルに影響する
export const idSchema = z.string().uuid();
サードパーティライブラリ
外部のZodスキーマを使用している場合は、再作成が必要になることがあります。
// 使わない: externalLibrary.schema
// 代わりに: @outputai/core の z でスキーマを再作成する
関連する問題
- スキーマは正しいのに型エラーが引き続き発生する場合は、
output-error-missing-schemasを確認してください - インポートが正しいのにバリデーションが失敗する場合は、スキーマ定義が実際のデータと一致しているか確認してください
原文(English)を表示
Fix Zod Import Source Issues
Overview
This skill helps diagnose and fix a common issue where Zod schemas are imported from the wrong source. Output SDK requires schemas to be imported from @outputai/core, not directly from zod.
When to Use This Skill
You're seeing:
- "incompatible schema" errors
- Type errors at step boundaries
- Schema validation failures when passing data between steps
- Errors mentioning Zod types not matching
- "Expected ZodObject but received..." errors
Root Cause
The issue occurs when you import z from zod instead of @outputai/core. While both provide Zod schemas, they create different schema instances that aren't compatible with each other within the Output SDK context.
Why this matters: Output SDK uses a specific version of Zod internally for serialization and validation. When you use a different Zod instance, the schemas are technically different objects even if they define the same shape.
Symptoms
Error Messages
Error: Incompatible schema types
Error: Schema validation failed: expected compatible Zod instance
TypeError: Cannot read property 'parse' of undefined
Code Patterns That Cause This
// WRONG: Importing from 'zod' directly
import { z } from 'zod';
const inputSchema = z.object( {
name: z.string()
} );
Solution
Step 1: Find All Zod Imports
Search your codebase for incorrect imports:
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
Step 2: Update Imports
Change all imports from:
// Wrong
import { z } from 'zod';
To:
// Correct
import { z } from '@outputai/core';
Step 3: Verify No Direct Zod Dependencies
Check your imports don't accidentally use zod elsewhere:
grep -r "import.*zod" src/
All matches should show @outputai/core, not zod.
Complete Example
Before (Wrong)
// src/workflows/my-workflow/steps/process.ts
import { z } from 'zod'; // Wrong!
import { step } from '@outputai/core';
export const processStep = step( {
name: 'processData',
inputSchema: z.object( {
id: z.string()
} ),
outputSchema: z.object( {
result: z.string()
} ),
fn: async input => {
return { result: `Processed ${input.id}` };
}
} );
After (Correct)
// src/workflows/my-workflow/steps/process.ts
import { z, step } from '@outputai/core'; // Correct!
export const processStep = step( {
name: 'processData',
inputSchema: z.object( {
id: z.string()
} ),
outputSchema: z.object( {
result: z.string()
} ),
fn: async input => {
return { result: `Processed ${input.id}` };
}
} );
Verification Steps
1. Check for remaining wrong imports
# Should return no results
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
2. Build the project
npm run output:worker:build
3. Run the workflow
npx output workflow run <workflowName> '<input>'
Prevention
ESLint Rule (if using ESLint)
Add a rule to prevent direct zod imports:
// .eslintrc.js
module.exports = {
rules: {
'no-restricted-imports': [ 'error', {
paths: [ {
name: 'zod',
message: "Import { z } from '@outputai/core' instead of 'zod'"
} ]
} ]
}
};
IDE Settings
Configure your editor to auto-import from @outputai/core:
For VS Code, add to settings.json:
{
"typescript.preferences.autoImportFileExcludePatterns": ["zod"]
}
Common Gotchas
Mixed Imports in Same File
Even one wrong import can cause issues:
import { z } from '@outputai/core';
import { z as zod } from 'zod'; // This causes problems!
Indirect Dependencies
If a utility file uses the wrong import and is shared:
// utils/schemas.ts
import { z } from 'zod'; // Wrong! This affects all files using these schemas
export const idSchema = z.string().uuid();
Third-Party Libraries
If using external Zod schemas, you may need to recreate them:
// Don't use: externalLibrary.schema
// Instead: recreate the schema with @outputai/core's z
Related Issues
- If schemas are correct but you still see type errors, check
output-error-missing-schemas - For validation failures with correct imports, verify schema definitions match actual data
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。