Files
genai-toolbox/docs/en/samples/pre_post_processing/python.md
Twisha Bansal 5b107c53f3 docs: make processing docs consistent across languages (#2497)
## Description

> Should include a concise description of the changes (bug or feature),
it's
> impact, along with a summary of the solution

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
2026-02-18 08:30:17 +00:00

1.4 KiB

title, type, weight, description
title type weight description
Python docs 1 How to add pre- and post- processing to your Agents using Python.

Prerequisites

This tutorial assumes that you have set up MCP Toolbox with a basic agent as described in the local quickstart.

This guide demonstrates how to implement these patterns in your Toolbox applications.

Implementation

{{< tabpane persist=header >}} {{% tab header="ADK" text=true %}} Coming soon. {{% /tab %}} {{% tab header="Langchain" text=true %}} The following example demonstrates how to use ToolboxClient with LangChain's middleware to implement pre- and post- processing for tool calls.

{{< include "python/langchain/agent.py" >}}

You can also add model-level (wrap_model) and agent-level (before_agent, after_agent) hooks to intercept messages at different stages of the execution loop. See the LangChain Middleware documentation for details on these additional hook types. {{% /tab %}} {{< /tabpane >}}

Results

The output should look similar to the following.

{{< notice note >}} The exact responses may vary due to the non-deterministic nature of LLMs and differences between orchestration frameworks. {{< /notice >}}

AI: Booking Confirmed! You earned 500 Loyalty Points with this stay.

AI: Error: Maximum stay duration is 14 days.