# How aisuite Extracts Thinking and Reasoning Content from LLM Responses

> Discover how aisuite extracts thinking and reasoning content from LLM responses by parsing structured tags, isolating chain-of-thought into a dedicated field for clear analysis.

- Repository: [Andrew Ng/aisuite](https://github.com/andrewyng/aisuite)
- Tags: how-to-guide
- Published: 2026-06-15

---

**aisuite extracts thinking content by parsing structured reasoning tags in provider responses, isolating the internal chain-of-thought into a dedicated `reasoning_content` field while returning clean, tag-free text in the standard `content` field.**

The `andrewyng/aisuite` library normalizes how developers interact with LLMs that return internal reasoning steps. When using models that expose their deliberation process, understanding how aisuite handles thinking and reasoning content extraction ensures you can log model logic without exposing raw markup to end users.

## The Message Model Architecture

At the core of this workflow is the **Message** class, which defines a `reasoning_content` attribute alongside the traditional `content` field. This dual-field architecture allows the framework to store private model reasoning separately from the final generated answer.

When a provider returns a response containing thinking tokens, the client-side implementation populates both fields: the full reasoning trace is assigned to `message.reasoning_content`, while the sanitized text—with reasoning tags and delimiters removed—populates `message.content`.

## Client-Side Extraction Implementation

The extraction logic resides in the client’s response processing layer, where raw strings from LLM providers are parsed before being wrapped in the unified `Message` interface. The workflow detects specific delimiters—typically XML-style tags or provider-specific markers—that wrap the model’s internal reasoning.

According to the source code, the implementation follows this pattern:

```python

# Processing logic in aisuite client response handling

if "<thinking>" in raw_content:
    # Split to isolate reasoning from the final answer

    thinking_content = raw_content.split("<thinking>", 1)[1].split("</thinking>", 1)[0]
    message.reasoning_content = thinking_content
    
    # Drop the private reasoning from user-facing answer

    clean_content = raw_content.replace(f"<thinking>{thinking_content}</thinking>", "").strip()
    message.content = clean_content

```

This approach ensures that **reasoning_content** persists for debugging, evaluation, or audit trails while the user receives only the final model output without internal deliberation noise.

## Provider Normalization Strategy

Different LLM providers format reasoning content differently—some use `<thinking>` tags, others embed reasoning in JSON metadata or custom XML structures. The aisuite client normalizes these variations during the extraction phase, ensuring the `Message` object presents a consistent interface regardless of whether you are using Anthropic, DeepSeek, or other reasoning-capable models.

For providers that return reasoning as a distinct API field rather than inline text, the client maps that field directly to `reasoning_content` without string splitting, maintaining the abstraction while preserving the data.

## Summary

- aisuite treats thinking content as a **first-class payload** within the `Message` model via the `reasoning_content` attribute.
- **Client-side parsing** detects reasoning delimiters in raw LLM responses and splits the text to isolate internal deliberations from final answers.
- The extraction workflow **sanitizes the visible content** field by removing reasoning tags before returning the response to the caller.
- This architecture provides **provider-agnostic consistency**, normalizing how reasoning is accessed across different LLM backends that expose chain-of-thought.

## Frequently Asked Questions

### How do I access extracted reasoning content in aisuite?

After calling `client.chat.completions.create()`, access the `reasoning_content` attribute on the returned message object: `response.choices[0].message.reasoning_content`. This field contains the model's internal chain-of-thought when the underlying provider supports reasoning extraction, otherwise it returns `None`.

### Does aisuite preserve reasoning tags in the main content field?

No. The library explicitly removes reasoning tags and delimiters from the `content` field to prevent leaking internal deliberations to end users. The raw reasoning is stored separately in `reasoning_content`, allowing you to control whether and how that information is displayed or logged in your application.

### Which LLM providers support thinking content extraction in aisuite?

aisuite supports reasoning extraction for providers that return thinking content, including models like Claude 3.7 Sonnet, DeepSeek R1, and other reasoning-capable LLMs. The client automatically detects and extracts reasoning when present in the provider response format.

### Can I modify how aisuite parses reasoning content?

The parsing logic is built into the client-side request handling and provider-specific adapters within the aisuite source. To customize extraction behavior, you would need to modify the provider implementation files or post-process the raw response before it is normalized into the `Message` model.