Spot the bug in this LangChain `@tool` definition that uses a free-form docstring with no type hints
Click any words you think contain an error. Click again to unmark.
Without `query: str` annotation, `@tool` generates a schema with an untyped parameter and no per-arg description; the model has nothing to ground its tool call on and frequently passes the wrong shape.
Picture handing a kitchen helper a note that says "bring me an ingredient" with no further detail. They might bring a tomato, a bottle of soy sauce, or the entire spice rack, and they wouldn't be wrong, because you didn't say. The `@tool` decorator generates the model's recipe card automatically from your function's signature. If you don't write down what each ingredient is (the type) and what it's for (the per-arg description), the model gets a blank recipe and guesses. Annotate the parameters and add an `Args:` section, and now the model knows exactly what to bring.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Name the bug (missing type annotation + no Args docstring → degraded JSON Schema), describe the intermittent symptom, show both fix patterns (annotation + Google-style docstring vs explicit Pydantic args_schema), and close with CI snapshot testing and runtime validation as defense in depth.
Real products, models, and research that use this idea.
- LangChain's documentation explicitly shows the Google-style docstring pattern for `@tool` and warns that missing annotations degrade the generated schema.
- Anthropic's Claude tool-use guide stresses that tool descriptions and parameter descriptions directly govern tool-call quality, the model is only as good as the spec.
- OpenAI's function-calling docs emphasize parameter types and descriptions for the same reason, this is a cross-vendor concern, not a LangChain quirk.
- Production LangChain agents commonly add CI tests that snapshot tool JSON Schemas to catch regressions when refactors strip type hints.
What an interviewer would ask next. Try answering before peeking at the approach.
QShow how you'd convert this tool to use an explicit `args_schema` with a Pydantic model, and explain when you'd reach for that pattern.
QWalk through a CI test that catches this class of bug before it ships.
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Skipping type annotations because "it's just a string". The annotation isn't for you, it's for the JSON Schema the model sees, which is how the model knows how to call your tool correctly.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.