{"slug": "the-prompt-your-sdk-sends-is-not-the-prompt-you-wrote", "title": "The prompt your SDK sends is not the prompt you wrote", "summary": "A tool called \"agenttap\" created by a developer who discovered that SDKs often modify prompts before sending them to AI APIs, causing discrepancies between what developers think they're sending and what actually reaches the API. Agenttap is an httpx transport layer that intercepts outbound HTTP requests, captures the actual JSON payload sent over the wire, and allows developers to replay, diff, and debug these requests to catch unintended modifications like content normalization or leaked metadata. The tool works with any SDK that uses httpx (including Anthropic and OpenAI), adds approximately 0.4ms overhead per call, and includes features like a ring buffer for the last 500 records, response redaction, and disk persistence.", "body_md": "A reply from Claude came back nonsense. The system prompt looked fine in my code. The messages looked fine in my logs. So I added a print(messages)\nright before client.messages.create(...)\n. Still fine.\nI was looking in the wrong place. The SDK was building the request body. What hit the wire was not what I was printing.\nSo I wrote a httpx transport that intercepts the outbound request, dumps the actual JSON, and lets me diff what I think I sent against what I actually sent. I called it agenttap\n.\nHere is the captured request for a call I thought was a clean two-turn conversation:\n{\n\"model\": \"claude-opus-4-7\",\n\"max_tokens\": 1024,\n\"system\": \"You are a careful code reviewer.\",\n\"messages\": [\n{\n\"role\": \"user\",\n\"content\": [\n{\"type\": \"text\", \"text\": \"Review this diff:\\n\\n```\ndiff\\n+ foo\\n\n```\"}\n]\n},\n{\n\"role\": \"assistant\",\n\"content\": \"Looks fine to me.\"\n},\n{\n\"role\": \"user\",\n\"content\": \"What about edge cases?\"\n}\n],\n\"metadata\": {\"user_id\": \"u_8821\"}\n}\nThree things I did not write:\n[{\"type\": \"text\", \"text\": ...}]\nblock. My code passed a plain string. The SDK normalized it.metadata.user_id\nwas leaking from a default I set in the client constructor six commits ago and forgot.None of these would have shown up in logs of my own variables. They only show up at the wire.\npip install agenttap\n. Then:\nimport httpx\nfrom agenttap import TapTransport\nfrom anthropic import Anthropic\ntap = TapTransport(wrap=httpx.HTTPTransport())\nclient = Anthropic(http_client=httpx.Client(transport=tap))\nclient.messages.create(\nmodel=\"claude-opus-4-7\",\nmax_tokens=256,\nmessages=[{\"role\": \"user\", \"content\": \"hi\"}],\n)\nfor record in tap.records:\nprint(record.request_json)\nprint(record.response_status, record.duration_ms, \"ms\")\nThe transport sits underneath the SDK. It does not know or care that this is Anthropic. It works the same way with OpenAI's Python SDK, with the Google client, with anything that ends up calling httpx.\nIt captures four things per call:\nauthorization\nand x-api-key\nredacted to ***\n).The reason I built this was not just to look. I wanted to replay.\nfrom agenttap import replay\n# Pin a captured request as a fixture\ntap.save(\"fixtures/review_call.json\")\n# Later, replay the exact bytes\nresp = replay(\"fixtures/review_call.json\", api_key=os.environ[\"ANTHROPIC_API_KEY\"])\nAnd diff two recordings:\nfrom agenttap import diff_records\na = tap.records[0]\nb = tap.records[1]\nprint(diff_records(a, b))\n# - messages[0].content[0].text: \"Review this diff:...\"\n# + messages[0].content[0].text: \"Review this PR:...\"\n# - metadata.user_id: \"u_8821\"\n# + metadata.user_id: \"u_4410\"\nThat diff caught a regression last week where a prompt template change added a stray newline. The output still looked plausible, but the deterministic eval drifted. The wire diff showed me the exact byte.\nOverhead per call when capturing in memory: about 0.4 ms on my laptop for a 2 KB body. The transport buffers the response body so streaming is slightly different. If you want to keep streaming responses streaming, pass capture_response_body=False\nand only the request side is recorded.\nDefault ring buffer holds the last 500 records. You can flush to disk with tap.save_all(dir=\"taps/\")\nand rotate.\nA few honest limits.\nclaude-stream-rs\nor wire a separate handler.TapTransport(redact_headers=[\"x-my-auth\"])\n.If you are running agents in production and you have never looked at the literal JSON that left your process, do it once. You will find something.\nRepo: https://github.com/MukundaKatta/agenttap\nPyPI: pip install agenttap\nThis is one of a small set of focused libraries I publish for AI agent plumbing (snapshots, budgets, drift, repair). Built piece by piece from real incidents.", "url": "https://wpnews.pro/news/the-prompt-your-sdk-sends-is-not-the-prompt-you-wrote", "canonical_source": "https://dev.to/mukundakatta/the-prompt-your-sdk-sends-is-not-the-prompt-you-wrote-1o3l", "published_at": "2026-05-21 01:51:44+00:00", "updated_at": "2026-05-21 02:03:43.506351+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "artificial-intelligence"], "entities": ["Claude", "Anthropic", "agenttap", "httpx", "SDK"], "alternates": {"html": "https://wpnews.pro/news/the-prompt-your-sdk-sends-is-not-the-prompt-you-wrote", "markdown": "https://wpnews.pro/news/the-prompt-your-sdk-sends-is-not-the-prompt-you-wrote.md", "text": "https://wpnews.pro/news/the-prompt-your-sdk-sends-is-not-the-prompt-you-wrote.txt", "jsonld": "https://wpnews.pro/news/the-prompt-your-sdk-sends-is-not-the-prompt-you-wrote.jsonld"}}