beta_tool validation errors reach the model as "Invalid arguments for function X" with no detail

オープン 初心者向け
#2,033 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@mangeshraut712 がすでに取り組んでいます。

2026年10月27日 から。

  • #2040 @mangeshraut712 による — マージされずにクローズ
  • #2041 @mangeshraut712 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

src/anthropic/lib/tools/_beta_functions.py から始めてください。BetaFunctionTool.call と BetaAsyncFunctionTool.call は pydantic.ValidationError から ValueError("Invalid arguments for function <name>") を送出します。sync と async の両方のパスで、そのメッセージにフィールドエラーの短い要約を含めてください。issue のスニペットで再現し、その後 tests/lib/tools/test_runners.py の 2009 行目あたりで期待される正確な文字列を更新してください。ツールの結果が失敗した引数と理由を示し、テストが通れば完了です。報告者が作業を希望しているため、始める前にスレッドで確認してください。

索引モデルが issue の本文から書いたものです。

説明

When the model calls a beta_tool function with arguments that fail validation, the tool result it gets back doesn't say what was wrong.

In src/anthropic/lib/tools/_beta_functions.py, BetaFunctionTool.call and BetaAsyncFunctionTool.call catch pydantic.ValidationError and raise ValueError("Invalid arguments for function ") from it. The tool runner then sends repr(exc) back as the tool result, so the model only sees the generic message and the field errors stay on cause. Since it doesn't know which argument was wrong, it can't really fix its next call and tends to retry the same thing.

There's a related smaller problem too. validate_call wraps the whole function, so a ValidationError raised inside the tool body (like building a pydantic model from bad data) gets the same "Invalid arguments" message, which makes a real bug in the tool look like the model's mistake.

Repro (Python 3.11, main at 202db72)

from anthropic import beta_tool
from anthropic.lib.tools._tool_dispatch import tool_error_content

@beta_tool
def set_temp(city: str, celsius: int) -> str:
    """Set temperature."""
    return f"{city} {celsius}"

try:
    set_temp.call({"city": "Paris", "celsius": "hot"})
except Exception as e:
    print(tool_error_content(e))

Output:

ValueError('Invalid arguments for function set_temp')

Expected

The message should name the argument and the reason, something like "Invalid arguments for function set_temp: celsius: Input should be a valid integer".

Fix idea

Add a short summary of the pydantic errors to the ValueError message in both the sync and async tools. The existing tests match on the message prefix, and the exact string in tests/lib/tools/test_runners.py around line 2009 would need updating.

If this sounds right, I would like to work on this.

主要言語
Python
スター
4k
フォーク
905
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anthropics/anthropic-sdk-python のほかの issue

anthropics/anthropic-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。