A failed lookup is its own answer.
Imagine a proposed AI assistant that checks a fictional parts catalog. A successful lookup can report in_stock or out_of_stock. A failed lookup supports neither answer. The small adapter between the HTTP client and the tool caller needs a way to say that the evidence is unavailable.
This guide tests that adapter before adding an agent. Professionals can adapt the pattern to a reviewed service contract. Hobbyists can run the fictional kit locally. Skeptics can inspect the inputs and outputs without accepting a claim about AI intelligence.
HTTPX is an open-source Python HTTP client. Its MockTransport accepts a handler that supplies predetermined responses instead of making network requests. We use that documented facility for authored teaching cases; this is not a new-release announcement.
Define what the caller is allowed to conclude.
Our fictional contract accepts a JSON object with item_id: "SKU-7" and an availability value of in_stock or out_of_stock. The adapter returns one of three explicit states:
- observed: the payload passed these small checks; preserve the reported availability.
- unavailable: the HTTP request failed or returned a non-success status; retain the reason.
- invalid_response: the body cannot support this lookup, even if its HTTP status is 200.
These names and validation rules are our application policy. A valid-shaped response can still be stale or wrong. Here, observed means accepted fictional payload, not verified real inventory.
Inspect the kit, then run it locally.
Use an existing Python 3.10+ installation. We ran Windows Python 3.13.15 with HTTPX 0.28.1; current primary sources checked October 31, 2026. The first block creates a fresh directory. Choose another name if it already exists.
New-Item -ItemType Directory -Path .\handoff-practice-2026-10-31 -ErrorAction Stop
Set-Location .\handoff-practice-2026-10-31
Invoke-WebRequest 'https://jabsystems.io/ai-anonymous/Social/fake-bad-day-practice.zip' -OutFile .\practice.zip
Expand-Archive -LiteralPath .\practice.zip -DestinationPath .\practice
Get-Content .\practice\handoff-practice-readme.txt
Get-Content .\practice\check-tool-handoff.pyRead the README and script before running the next block. The exercise creates a client with a mock transport, disables environment-derived configuration and supplies no real HTTP fallback.
python --version
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install httpx==0.28.1
.\.venv\Scripts\python.exe .\practice\check-tool-handoff.py | Set-Content -Encoding utf8 .\my-results.json
Get-Content .\my-results.jsonDownloading and installing dependencies uses the network. The exercise itself uses authored mock responses. A virtual environment isolates dependencies, not untrusted code. HTTPX is pinned directly; this is not a full transitive dependency lock.
What the local run actually showed.
The downloaded script asserts both the expected result and exactly one mock request per case. All ten authored cases passed in the stated environment:
- 200 with valid stock state:
observed / in_stock. - 200 with valid negative state:
observed / out_of_stock. - 503 and 401:
unavailablewithhttp_503andhttp_401respectively. - 200 with malformed JSON:
invalid_response / bad_json. - 200 missing availability, or with a Boolean instead:
invalid_response / unknown_availability. - 200 for the wrong item:
invalid_response / wrong_or_missing_item. - Raised ReadTimeout:
unavailable / timeout. - Raised ConnectError:
unavailable / transport_error.
Compare your output with the recorded report; your Python version may differ. These inputs are authored simulations, not captured AI mistakes or live API failures. The pass count describes these finite assertions only.
Make the error path visible.
import httpx
def handler(request):
return httpx.Response(503, json={"error": "maintenance"})
with httpx.Client(transport=httpx.MockTransport(handler),
trust_env=False) as client:
response = client.get("https://catalog.example.invalid/inventory/SKU-7")
print(response.status_code)
try:
response.raise_for_status()
except httpx.HTTPStatusError:
print("unavailable")
The smaller snippet actually printed 503, then unavailable. The complete kit adds JSON and field checks. As the HTTPX quickstart documents, raise_for_status() is the step that raises on a non-success response; merely receiving a response does not apply our tool policy.
The exception reference distinguishes status errors from request errors and places timeout exceptions under transport errors. The kit catches timeout exceptions before the broader request-error branch so its reason remains visible.
A simulated timeout does not test a clock.
Our mock handler directly raises ReadTimeout. That exercises exception handling without waiting. The timeout=2.0 argument in the complete exercise does not prove a two-second deadline works against a real service. HTTPX documents separate connect, read, write and pool timeouts in its timeout guide.
This client routes every request through its mock handler. Unexpected methods or URLs fail an assertion. That says nothing about other clients or code you add: MockTransport is not a machine-wide network sandbox.
The kit has no retry loop and performs no write operation. It does not test real authentication, DNS, TLS, latency, streaming, service freshness, rate limits, production recovery or the actual provider contract.
Carry uncertainty through the agent boundary.
Next, adapt the fixtures to your actual read-only service contract. Add staging checks for authentication, transport behavior, real response shapes and freshness. Then check that the agent preserves an unavailable or invalid-response result instead of inventing a confident inventory answer. That integration is a separate test and is not included here.
An optional review prompt to try later: “Review this tool result contract. For each unavailable or invalid-response state, propose wording that preserves uncertainty. Flag any path that treats a failed lookup as out_of_stock. Do not infer inventory.” This prompt is proposed and was not run against a model.
Tested: ten authored offline adapter cases, the smaller snippet and the extracted practice workflow on Windows. Not tested: any model, agent, real inventory service, actual timeout timing, production reliability, performance or other operating system. The useful artifact is a visible contract and reproducible examples.
Take the tool-handoff kit.
Practice ZIP · Complete exercise · Recorded results · Practice README · Review checklist
Original AI-generated conceptual portrait, visually reviewed. Simulated responses are labeled in the artwork. Primary sources checked October 31, 2026.

