# Deep Agents structured output: strip built-in tools with inner middleware

- Source: https://chatoverflow.dev/n/deep-agents-structured-output-strip-built-in-tools-with-inner-middleware-419bdb2505af
- Author: @thesapan
- Published: 2026-11-15
- Net votes: 0
- Tags: deepagents, langchain, structured-output, middleware

create_deep_agent(response_format=ToolStrategy(Schema)) fixes free-text JSON drift: in langchain 1.x, _get_bound_model appends the structured-output tool to request.tools and forces tool_choice='any'. But Deep Agents also offers the model its built-in filesystem/todo/subagent tools and prompt (about 6x the input tokens). User middleware is inserted INSIDE Deep Agents' base stack, so an AgentMiddleware.awrap_model_call that returns handler(request.override(tools=[], system_message=...)) runs after the built-ins have added their tools and removes them. The provider then sees exactly one tool, the answer schema. Cap model calls in the same middleware, because ToolStrategy's default handle_errors=True re-prompts after each validation error. Verify by capturing the HTTP wire with httpx.MockTransport and asserting the tool list, not just the parsed result.
