Skip to main content

unswallow (Python)

The 1:1 Python mirror of the unswallow TypeScript library: detect and recover tool calls trapped inside a model's reasoning channel — the reasoning-channel swallow bug class across vLLM, SGLang, and llama.cpp.

pip install unswallow
from unswallow import check_and_rescue

result = check_and_rescue(
    raw_provider_response,
    engine_hint="vllm",
    engine_version="0.19.0",
    tool_schemas=my_tools,
)

if result.recovered and result.recovered_response:
    return result.recovered_response   # tool_calls is populated, finish_reason is "tool_calls"

Same interface, same semantics, same bundled matrix data (synced from packages/matrix/data/engine-matrix.json), zero runtime dependencies, Python 3.9+.

Streaming

from unswallow import check_and_rescue_stream

result = await check_and_rescue_stream(
    chunk_iterable,          # AsyncIterable of OpenAI-compatible SSE chunks
    engine_hint="vllm",
    engine_version="0.19.0",
    on_leak=logger.warning,  # live pattern-C signal, optional
)

Or accumulate manually with StreamAccumulator (.push(chunk) / .end()).

History hygiene (Pattern D)

from unswallow import sanitize_history, strip_reasoning_tags

clean = sanitize_history(messages)
text = strip_reasoning_tags(assistant_text)  # "< thinking>\nplan\n< response>\nanswer" -> "answer"

CLI

unswallow check                                   # bundled self-test demo (vLLM #39056)
unswallow check --fixture response.json           # captured raw response
unswallow check --endpoint http://localhost:8000/v1 --model Qwen/Qwen3.5-35B-A3B-FP8 --engine vllm --version 0.19.0
unswallow matrix

Exit codes for live probes: 0 = not affected, 1 = affected, 2 = error.

Development

cd packages/python
python -m unittest discover -s tests -v    # stdlib-only test suite

The engine matrix is bundled as data — after editing packages/matrix/data/engine-matrix.json, run python packages/python/scripts/sync_matrix.py from the repo root. CI verifies the copies stay identical.

Everything else — patterns, confidence scoring, the false-positive guard, the benchmark corpus and the engine matrix — is documented in the repository root README.

Release files for unswallow 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unswallow 0.1.2
File Size Uploaded
unswallow-0.1.2.tar.gz 22.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unswallow 0.1.2
File Interpreter ABI Platform
unswallow-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 44.3 kB

Release files / unswallow-0.1.2.tar.gz

Download URL unswallow-0.1.2.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0a26b83b8eee83ac50eb4ef3ba5f319583684525722ea92482a3de0f436a4517
BLAKE2b-256 checksum
How to use checksums
11320deb38d3cdaddb254385516788b2b0ae9f1b679a3d2a9247500425188780
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / unswallow-0.1.2-py3-none-any.whl

Download URL unswallow-0.1.2-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a299a3d554f57406a1d09e3eed7de9c603befadeb2fad2111ac4e03bbe0bc2ba
BLAKE2b-256 checksum
How to use checksums
13f8d4ae9ed881d8c13f9227dd23cfbae96dd5e0f8865f97105a881f1ef1e431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.3

2 release files

This release

0.1.2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page