講座 › 分野4 評価、テスト、デバッグ
4.1 デバッグとエラー処理
エラーの種類で直し方が決まる。一時的なものは間隔を空けて再試行、形式の誤りは直す。原因が「つなぎ側」か「モデルの出力」かを切り分ける。
エラーの種類を見分ける 読了

400(invalid_request_error)は、リクエストの形式や中身の誤りです。再試行しても直らないので、リクエストを直します。429(rate_limit_error)は流量の上限や使用額の上限です。500(api_error)はAnthropic内部の想定外のエラー、529(overloaded_error)は一時的な混雑です。
出典:Errors
There’s an issue with the format or content of your request.https://platform.claude.com/docs/en/api/errors.md(取得 2026-11-17)
出典:Errors
Your organization has hit a rate limithttps://platform.claude.com/docs/en/api/errors.md(取得 2026-11-17)
出典:Errors
529 - `overloaded_error`: The API is temporarily overloaded.https://platform.claude.com/docs/en/api/errors.md(取得 2026-11-17)
復旧の戦略を選ぶ 読了

一時的なエラー(接続、流量の上限、5xx)は、間隔を指数関数的に広げて再試行します。公式のSDKは、これを既定で2回自動で行い、retry-after のヘッダーがあれば従います。ただし、月の使用額の上限に達した429には retry-after が無く、再試行しても上限が戻るまで失敗し続けます。エラーが続く場合は、リクエストIDを添えて問い合わせます。
出典:Errors
The official SDK automatically retries transient failures (such as connection errors, rate limits, and 5xx server errors) with exponential backoff, twice by default, honoring the `retry-after` header when present.https://platform.claude.com/docs/en/api/errors.md(取得 2026-11-17)
出典:Rate limits
Retrying, including the SDK’s automatic retries, fails until access resumes.https://platform.claude.com/docs/en/api/rate-limits.md(取得 2026-11-17)
つなぎ側か、モデルの出力か 読了

応答が途中で切れてJSONの解析に失敗した場合、まず stop_reason を見ます。max_tokens なら、出力の上限に達して切れたので、モデルの問題ではなく設定の問題です。end_turn なら最後まで答えています。refusal なら、Claudeが回答を断っています。ツールが失敗したときは、tool_result に is_error を付けて返すと、Claudeが状況を理解して対応できます。
出典:Handling stop reasons
The response reached your `max_tokens` limit.https://platform.claude.com/docs/en/build-with-claude/handling-stop-re…(取得 2026-11-17)
出典:Handling stop reasons
Claude completed its response naturally. | Use the response.https://platform.claude.com/docs/en/build-with-claude/handling-stop-re…(取得 2026-11-17)
出典:Handle tool calls
Set to `true` if the tool execution resulted in an error.https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-t…(取得 2026-11-17)
トレースで失敗のパターンを見つける 読了

トレース(トランスクリプト)は、出力、ツール呼び出し、推論、途中の結果を含む、1回の実行の完全な記録です。最後のメッセージだけでなく、環境の最終状態(例:予約が本当にデータベースに入ったか)と合わせて見ます。Agent SDKは、OpenTelemetryでトレースを外部の監視の仕組みに送れます。ツールがまったく呼ばれない場合は、ツール名の重複や、あいまいなスキーマが原因のことがあります。
出典:Demystifying evals for AI agents
is the complete record of a trial, including outputs, tool calls, reasoning, intermediate resultshttps://www.anthropic.com/research/demystifying-evals-for-ai-agents(取得 2026-11-17)
出典:Demystifying evals for AI agents
the outcome is whether a reservation exists in the environment’s SQL databasehttps://www.anthropic.com/research/demystifying-evals-for-ai-agents(取得 2026-11-17)
出典:Agent SDK observability
Export traces, metrics, and events from the Agent SDK to your observability backend using OpenTelemetry.https://code.claude.com/docs/en/agent-sdk/observability.md(取得 2026-11-17)
出典:Troubleshooting tool use
Tool name collision or overly generic schemahttps://platform.claude.com/docs/en/agents-and-tools/tool-use/troubles…(取得 2026-11-17)
- 400は直す、429・5xx・529は間隔を空けて再試行。ただし使用額の上限の429は待つしかない。
出典:Errors
Retry the request with exponential backoff; if the error persists, contact support with the request ID.
https://platform.claude.com/docs/en/api/errors.md(取得 2026-11-17) - JSONが壊れたら、まず stop_reason。max_tokens なら上限の設定の問題。
出典:Handling stop reasons
Learn what each stop_reason value means and how to handle truncation, tool use, paused turns, and refusals in your application.
https://platform.claude.com/docs/en/build-with-claude/handling-stop-re…(取得 2026-11-17)