# Module LittleGhost::Support::OutputTruncation

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Support/OutputTruncation.html

OutputTruncation keeps large tool results within a predictable context budget
without breaking UTF-8. Its byte-to-token estimate is deliberately
approximate; use a provider tokenizer when exact accounting is required.

## Constants

### `APPROX_BYTES_PER_TOKEN`

Byte estimate used when no provider tokenizer is available.

## Instance methods

<a id="method-i-approx_bytes_for_tokens"></a>
### `#approx_bytes_for_tokens`

```ruby
#approx_bytes_for_tokens(tokens)
```

Converts a token budget to its approximate byte budget.

<a id="method-i-approx_token_count"></a>
### `#approx_token_count`

```ruby
#approx_token_count(text)
```

Estimates tokens from the UTF-8 byte length of `text`.

<a id="method-i-approx_tokens_from_byte_count"></a>
### `#approx_tokens_from_byte_count`

```ruby
#approx_tokens_from_byte_count(bytes)
```

Converts bytes to an approximate token count, rounded up.

<a id="method-i-truncate_middle_with_token_budget"></a>
### `#truncate_middle_with_token_budget`

```ruby
#truncate_middle_with_token_budget(text, max_tokens)
```

Keeps text within budget or produces a middle-truncated UTF-8 string and the
original approximate token count.
