The Exit Transformer AI Policy customizes the responses that AI Gateway generates itself. You write one or more Lua functions that receive the response status, body, and headers, and return the values that AI Gateway sends to the client. Use it to change a message or status code, add headers, or reshape the structure of an error response so that it matches the format your clients expect.
The Exit Transformer Policy only affects responses that AI Gateway generates, such as an authentication error or a response from the Request Termination Policy. It doesn’t change responses that come from an upstream LLM provider, an AI Agent, or an upstream MCP server.
Anyone who can create or edit an Exit Transformer Policy can run Lua code on your data plane, within the limits of the sandbox.