Output SDK のワークフロー(処理の流れ)で Zod スキーマ(データ形式の定義)のインポートの問題を解決します。 次のような場合に使用: - 「互換性のないスキーマ」というエラーが表示されている - ステップの境界(処理の段階の切り替わり)で型エラーが発生している - スキーマの検証に失敗している - 複数のステップ間でスキーマが一致していない
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.
このスキルは、Zod スキーマ(データ構造の定義)が間違ったソースからインポートされている一般的な問題の診断と修正を支援します。Output SDK では、スキーマは zod から直接ではなく @outputai/core からインポートする必要があります。
以下のようなエラーが表示されている場合:
この問題は、zod から直接 z をインポートする代わりに @outputai/core から 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
// 間違い: 'zod' から直接インポート
import { z } from 'zod';
const inputSchema = z.object( {
name: z.string()
} );
コードベース内で誤ったインポートを検索します:
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
以下から:
// 間違い
import { z } from 'zod';
以下に変更します:
// 正解
import { z } from '@outputai/core';
インポートが誤って他の場所で zod を使用していないか確認します:
grep -r "import.*zod" src/
すべての検索結果は zod ではなく @outputai/core を示していることを確認してください。
// src/workflows/my-workflow/steps/process.ts
import { z } from 'zod'; // 間違い!
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}` };
}
} );
// src/workflows/my-workflow/steps/process.ts
import { z, 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}` };
}
} );
# 結果が表示されないことを確認
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
npm run output:worker:build
npx output workflow run <workflowName> --input '<input>'
Zod を直接インポートするのを防ぐルールを追加します:
// .eslintrc.js
module.exports = {
rules: {
'no-restricted-imports': [ 'error', {
paths: [ {
name: 'zod',
message: "Import { z } from '@outputai/core' instead of 'zod'"
} ]
} ]
}
};
エディタを設定して @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'; // 間違い! これはこのスキーマを使用するすべてのファイルに影響します
export const idSchema = z.string().uuid();
外部の Zod スキーマを使用している場合、再作成が必要な場合があります:
// 使用しないでください: externalLibrary.schema
// 代わりに: @outputai/core の z でスキーマを再作成してください
output-error-missing-schemas を確認してください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.
You're seeing:
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.
Error: Incompatible schema types
Error: Schema validation failed: expected compatible Zod instance
TypeError: Cannot read property 'parse' of undefined
// WRONG: Importing from 'zod' directly
import { z } from 'zod';
const inputSchema = z.object( {
name: z.string()
} );
Search your codebase for incorrect imports:
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
Change all imports from:
// Wrong
import { z } from 'zod';
To:
// Correct
import { z } from '@outputai/core';
Check your imports don't accidentally use zod elsewhere:
grep -r "import.*zod" src/
All matches should show @outputai/core, not zod.
// 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}` };
}
} );
// 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}` };
}
} );
# Should return no results
grep -r "from 'zod'" src/
grep -r 'from "zod"' src/
npm run output:worker:build
npx output workflow run <workflowName> --input '<input>'
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'"
} ]
} ]
}
};
Configure your editor to auto-import from @outputai/core:
For VS Code, add to settings.json:
{
"typescript.preferences.autoImportFileExcludePatterns": ["zod"]
}
Even one wrong import can cause issues:
import { z } from '@outputai/core';
import { z as zod } from 'zod'; // This causes problems!
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();
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
output-error-missing-schemas原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。