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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unswallow-0.2.0.tar.gz | 30.0 kB | Without provenance | Details for unswallow-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unswallow-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for unswallow-0.2.0-py3-none-any.whl |
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
|
Security for unswallow 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.