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

Abierto Apto para principiantes
#2,033 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@mangeshraut712 ya está trabajando en esto.

Desde el 27/10/2026.

  • #2040 de @mangeshraut712 — cerrado sin fusionar
  • #2041 de @mangeshraut712 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Comienza en src/anthropic/lib/tools/_beta_functions.py: BetaFunctionTool.call y BetaAsyncFunctionTool.call lanzan ValueError("Invalid arguments for function <name>") desde un pydantic.ValidationError; incluye un breve resumen de los errores de campo en ese mensaje tanto para la ruta síncrona como para la asíncrona. Reprodúcelo con el fragmento del issue y luego actualiza la cadena esperada exacta en tests/lib/tools/test_runners.py alrededor de la línea 2009. Listo cuando el resultado de la herramienta nombre el argumento fallido y el motivo y las pruebas pasen. Ten en cuenta que el reportante pidió trabajar en ello, así que consulta en el hilo antes de empezar.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
4k
Forks
905
Merge medio
5 min
PR fusionados (30 d)
1

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de anthropics/anthropic-sdk-python

Todos los issues de anthropics/anthropic-sdk-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.