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

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.2.0
File Size Uploaded
unswallow-0.2.0.tar.gz 30.0 kB Details

Built distribution (wheel)

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

Total release size: 55.1 kB

Release files / unswallow-0.2.0.tar.gz

Download URL unswallow-0.2.0.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bd60eb57c255ed4cb9a23f3abe766f2a6da543dc0e2f40f4b09d245c2ab29815
BLAKE2b-256 checksum
How to use checksums
637356e8cba4443343ffa5608cef14aa41c467c26a336439a3a1abf0080585fc
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.2.0-py3-none-any.whl

Download URL unswallow-0.2.0-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55cfb7163147e1a4e5419c0bc8e718c416e31a76a5583d80e026b3c52710b13f
BLAKE2b-256 checksum
How to use checksums
0b60fac3fe9e7d84d90ce56ac32963117c519c9265cb66ca53e70f150f0981b5
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

This release

0.2.0 This release

2 release files

0.1.3

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