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.3

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.3
File Size Uploaded
unswallow-0.1.3.tar.gz 25.9 kB Details

Built distribution (wheel)

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

Total release size: 50.2 kB

Release files / unswallow-0.1.3.tar.gz

Download URL unswallow-0.1.3.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2b7a46e94e187f2481492f94bac4aa3d864372577d0bb74787c1a0411e260dd5
BLAKE2b-256 checksum
How to use checksums
d3c1a040bf57c471d4d8c1659f27e3710157470ea11e3eb5f93a227e70641e31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

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

Download URL unswallow-0.1.3-py3-none-any.whl
Size 24.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
daa0dff12c6f7ed2049ee699dd14cf55d19e9ab5c5b310546993422246fc2d28
BLAKE2b-256 checksum
How to use checksums
b360f53e6103c4f4ea20ffafa649f9632aa11b06eb9b758bfde639fe41730660
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.3 This release

2 release files

0.1.2

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