Tool-Fehler, die das Modell sehen kann
Geben Sie Fehler zurück, die die KI lesen und beheben kann.
Tool-Fehler, die das Modell sehen kann ist eine kostenlose MCP Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des MCP Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der MCP Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Errors Are Just More Context
When a tool fails, the AI does not crash. It simply reads your error as context and decides what to do next, just like any result.
A Good Error Is Actionable
Write the error for a reader who can act on it. City not found beats Exception, because the model can ask the user to fix the city.
Return an Error String
The simplest pattern is returning a clear message string when something is wrong, so the model reads exactly what failed.
@mcp.tool()
def get_user(uid: int) -> str:
if uid < 1:
return "Error: uid must be positive."Raise to Flag a Tool Error
You can also raise a normal Python exception. FastMCP catches it and reports a tool error back to the model, not a server crash.
@mcp.tool()
def divide(a: float, b: float) -> float:
if b == 0:
raise ValueError("b cannot be zero")
return a / bisError Marks the Result
Under the hood, a failed tool call returns content with isError set true. That flag tells the client this result describes a failure.
The Model Can Recover
A readable error lets the AI retry with better input or explain the issue to the user, turning a failure into a helpful next step. 🔁
Say What and Why
Good errors name what failed and why. File missing: report.csv is far more useful to the model than a bare Not found.
Suggest a Fix
When you can, hint at the remedy inside the error. Date must be YYYY-MM-DD lets the model correct itself on the very next call.
if not iso_date:
raise ValueError("Date must be in YYYY-MM-DD format")Never Leak Internals
Errors reach the model and often the user, so keep secrets, raw stack traces, and connection strings out of the message you return.
Validate, Then Error Early
Check arguments first and return the error before doing real work. Failing fast keeps your tool predictable and easy to reason about.
Errors Are Part of the Contract
Treat failures as designed output. A tool that names its likely errors is as useful to the model as one that documents its success.
Quick Check
Why write tool errors as clear, readable messages?
Recap
Tool errors are context the model reads: make them clear, say what and why, suggest a fix, and never leak internals. ✅
Häufig gestellte Fragen
Ist die Lektion „Tool-Fehler, die das Modell sehen kann“ kostenlos?
Ja — der vollständige Text von „Tool-Fehler, die das Modell sehen kann“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des MCP Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der MCP Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Tool-Fehler, die das Modell sehen kann“?
Geben Sie Fehler zurück, die die KI lesen und beheben kann. Du übst MCP Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um MCP Academy zu starten?
Keine Vorkenntnisse erforderlich. MCP Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Tool-Fehler, die das Modell sehen kann“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser MCP Academy-Lektion Code schreiben und ausführen?
Ja. Jede MCP Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Tool-Fehler, die das Modell sehen kann
- Protokollfehler oder Tool-Fehler
- Eingaben vor der Ausführung validieren
- Sicher fehlschlagen, niemals hängen