Your agent gets a tool call wrong in two ways: it calls the wrong tool, or it calls the right tool with arguments the tool rejects. The second is the common one, and it is silent, because the agent retries with new wording until the call succeeds and the conversation still ends well; the only signs of the problem are the failed calls in the trace and the extra model calls they cost.
How a bad tool call shows up
- As a failed criterion. The judge reads your agent's traces, so a criterion such as
The agent creates the returnfails when the call never succeeded, and the judge writes the tool and the error into its reasoning. - As a passing scenario with retries inside it. The verdict is green and the conversation is a single reply, but behind that reply there are six model calls in the trace. Press View trace on the turn and you will see the same tool call twice in a row, the first one followed by the error text as its result. When your tools are traced, each call also appears as its own span.

To make the second case fail on its own, add a criterion on the process as well as the outcome, such as The agent does not call check_return_eligibility more than once for the same order.
Step 1: Get the tool contract fixed
Run the suite once, then paste this into Langy or into your coding agent:
Use the langwatch CLI to read the last run of the last test suite I ran; ask me which one if it isnot clear from our conversation. Find every tool call that a tool rejected or that my agent retried,tell me what the model saw as the error, and fix the tool descriptions, the parameter schemas andthe error messages so the first call succeeds. Tell me what you found before you change anything.The agent comes back with a change to the tool contract. When you review it, these are the properties of a good contract, the most effective first:
- The accepted values are in the parameter description, or better, in the schema. With an enum in the schema the model does not guess at all; a description that lists the values is the next best thing.
- A more detailed error message, which says which parameter was rejected and which values it accepts, so the model can fix the call instead of guessing again.
- The tool validates the call at its boundary and rejects it with that same message before the call reaches your service.
- One tool per job. Merge a tool that needs three calls to return one answer into one call, or add a second tool next to it that returns the answer in one step.
- The harness caps the retries, so after the second failure on the same tool the agent escalates or asks the user instead of trying a third time.
For example, the same tool before and after the first three changes on the list, which put the accepted values in the description, return a more detailed error message and validate at the boundary:
def check_return_eligibility(order_id: str, reason: str) -> str: """Check if an order can be returned.""" ...REASONS = ("defective", "incorrect_item", "not_as_expected", "remorse")def check_return_eligibility(order_id: str, reason: str) -> str: """Check if an order can be returned. reason must be one of: defective, incorrect_item, not_as_expected, remorse. Returns the return window and whether the order is inside it. """ if reason not in REASONS: raise ValueError(f"reason must be one of: {', '.join(REASONS)}") ...The model reads the docstring as the tool description, so the first version makes it guess the value of reason while the second makes the first call succeed. Every closed parameter needs the same treatment: in the example, the tool rejected refund_method on create_return as often as reason.
Step 2: Assert on the tool calls
On the platform, write the tool calls into the criteria of the scenario:
The agent looks up the order before it answersThe agent calls check_return_eligibility once, with one of the accepted reasonsThe agent creates the return and confirms the refund methodIn code, a script step checks the conversation state directly. has_tool_call checks that the agent called a tool at all, and a plain function can count the calls:
import pytestimport scenariodef eligibility_checked_once(state: scenario.ScenarioState): calls = [ call for message in state.messages if message["role"] == "assistant" for call in (message.get("tool_calls") or []) if call["function"]["name"] == "check_return_eligibility" ] assert len(calls) == 1, f"check_return_eligibility was called {len(calls)} times"@pytest.mark.asyncioasync def test_damaged_item_refund(): result = await scenario.run( name="damaged item refund", description="The customer received a damaged blender, order 1001, and wants a refund.", agents=[ReturnsAgent(), scenario.UserSimulatorAgent(), scenario.JudgeAgent(criteria=[ "The agent creates the return", "The agent confirms the refund method", ])], script=[ scenario.user(), scenario.agent(), eligibility_checked_once, scenario.proceed(), ], ) assert result.successSee Scenarios in code for the adapter and the script steps.
Step 3: Rerun and compare
Run the suite against the changed agent next to the one you deployed:
langwatch test-suite run "Returns" \ --target connected:returns-agent \ --target connected:returns-agent@production \ --waitThe changed side passes the new criteria, and each reply has fewer model calls behind it: in the example, three instead of five for the damaged blender return. Keep the criteria, because they are now the regression test for this tool. The Total cost and Average reply latency charts move more between two runs of the same agent than the removed retries move them, so read those two from a run with --repeat 3.
Common failures
- The agent still retries. The values are in the docstring and the model does not use them, so move them into the schema as an enum, or into the error message.
- The criterion fails on a scenario that should not call the tool. Scope the criterion to the situation,
When the customer asks for a return, the agent calls ..., and the judge applies the condition. - There are no tool spans in the trace. The tools are not instrumented. The rejected call is still visible as the tool result in the input of the next model call, which is what the judge reads, but to get a span per tool call decorate the tool functions: see Linking your traces.
- The judge calls a criterion about the tool calls inconclusive. Either the trace arrived after the judge's thirty-second wait, or the project's data privacy policy redacts the tool names and contents from it. Rerun the scenario, and check the policy.