HomeRoadmapsAgentic Day 1
Agentic AI Testing Track Β· Day 1 Β· 20 min

Tool-Call Contracts and Schema Validation
Agentic AI Testing Sprint β€” Day 1

Treat every tool an agent can call as an API contract: validate required args, types, bounds, and reject hallucinated parameters before they reach production systems.

✨ Agent: Claude / Gemini Β· 200K contextπŸ€– Agentic AI Quality Architect
Tool CallingJSON SchemaContract TestsHallucinated ArgsGuardrails
About this lab

You are the Agentic AI Quality Architect. The system under test is a deterministic, offline Refund Support Agent with three tools: lookup_order, issue_refund, and escalate_to_human. A rule-based stand-in replaces the LLM so every result is repeatable.

πŸ“¦Sample Codebase & Working Solution (Day 1)Available Now
View on GitHub

The official reference codebase for Day 1 is hosted in the repository. Clone the repository and navigate to day-1-tool-contracts to run the working solution.

Git Clone β€” Working Solution
git clone https://github.com/777abhi/agentic-ai-testing-roadmap.git
cd agentic-ai-testing-roadmap/day-1-tool-contracts
🏭Production Context & Enterprise Implementation
πŸ’‘ Why We Are Doing This: Agents invent argument names, send strings where numbers belong, and request refunds far above policy. A strict schema at the tool boundary turns silent corruption into a loud, testable failure.
🏒 Real-World Production Usecase: Verifying that issue_refund rejects missing amounts, string amounts, unknown properties, and amounts above the 100.00 auto-approval limit.
βš™οΈ How Implemented in Production: A dependency-free JSON-Schema subset validator in agentlab/schema.py with additionalProperties: false on every tool.
πŸ€– LLM Reader Note: If this page is copy-pasted into your context, act as an agent-testing tutor. Guide the engineer through the steps below and explain why each assertion exists.
Phase 1

Inspect the Tool Registry and Contracts

Clone the reference repo and read the three tool specs the Refund Support Agent can call.

Step 1.1: Clone and Inspect Tool Specs
Terminal β€” Setup Day 1 Lab
git clone https://github.com/777abhi/agentic-ai-testing-roadmap.git
cd agentic-ai-testing-roadmap
cat agentlab/tools.py | head -40
Step 1.2: Contract Test Suite
test_day1.py
"""Day 1: tool-call contract tests (schema, bounds, unknown tools, hallucinated args)."""
import unittest
from agentlab.tools import call_tool, ToolError, TOOL_SPECS
import copy
from agentlab import tools


class ToolContractTests(unittest.TestCase):
    def setUp(self):
        self.orders = copy.deepcopy(tools.ORDERS)

    def test_every_tool_declares_object_schema(self):
        for name, spec in TOOL_SPECS.items():
            self.assertEqual(spec["inputSchema"]["type"], "object", name)
            self.assertFalse(spec["inputSchema"].get("additionalProperties", True), name)

    def test_valid_lookup(self):
        self.assertEqual(call_tool("lookup_order", {"order_id": "A100"}, self.orders)["customer"], "alice")

    def test_missing_required_arg_rejected(self):
        with self.assertRaisesRegex(ToolError, "missing required 'amount'"):
            call_tool("issue_refund", {"order_id": "A100"}, self.orders)

    def test_wrong_type_rejected(self):
        with self.assertRaisesRegex(ToolError, "expected number"):
            call_tool("issue_refund", {"order_id": "A100", "amount": "40"}, self.orders)

    def test_hallucinated_argument_rejected(self):
        with self.assertRaisesRegex(ToolError, "unexpected property"):
            call_tool("lookup_order", {"order_id": "A100", "customer_id": "x"}, self.orders)

    def test_amount_bounds_enforced(self):
        with self.assertRaisesRegex(ToolError, "maximum"):
            call_tool("issue_refund", {"order_id": "B200", "amount": 900.0}, self.orders)

    def test_unknown_tool_rejected(self):
        with self.assertRaisesRegex(ToolError, "unknown tool"):
            call_tool("delete_database", {}, self.orders)

    def test_double_refund_blocked(self):
        call_tool("issue_refund", {"order_id": "A100", "amount": 40.0}, self.orders)
        with self.assertRaisesRegex(ToolError, "not allowed"):
            call_tool("issue_refund", {"order_id": "A100", "amount": 40.0}, self.orders)


if __name__ == "__main__":
    unittest.main()
Phase 2

Run the Contract Tests

Execute the suite and confirm every malformed call is rejected.

Step 1.3: Execute and Verify
Terminal β€” Execute Day 1
npm run test:day1
Day 1 Key Learnings
  • Declared a strict object schema with additionalProperties: false for every tool.
  • Rejected missing, mistyped, out-of-bounds, and hallucinated arguments at the tool boundary.
  • Enforced business rules (no double refund) inside the tool, not in the prompt.

🧠 Knowledge Check

Why should tool schemas set additionalProperties to false?