Skip to main content

langchain-id-aliaser

Reversible UUID / ID aliasing for LangChain & LangGraph. Replace long identifiers with short, stable aliases before they reach the LLM — and restore the originals on the way back, including in the model's outgoing tool calls.

f47ac10b-58cc-4372-a567-0e02b2c3d479   →   usr_a9Fk2
        (~15-19 tokens)                        (~2 tokens)

Why

  • Cheaper. A UUID tokenizes into ~15-19 tokens. In agent loops the same ids echo through tool calls, results, and state — the cost multiplies. Aliases are 1-2 tokens.
  • More accurate. LLMs frequently mangle or hallucinate long UUIDs. Short, stable aliases are far harder to corrupt, so tool calls round-trip correctly.

Install

pip install langchain-id-aliaser            # core only
pip install "langchain-id-aliaser[langchain]"  # + adapters

How it works

One dependency-free engine (IdAliaser) detects ids, aliases them, and restores them. Three thin adapters share that engine so behavior is identical everywhere:

Use case Adapter
Single call wrap_model(model)
Agent AliasMiddleware
Raw StateGraph alias_before_model / restore_after_model, or make_model_node

Core

from langchain_id_aliaser import IdAliaser

a = IdAliaser()                       # deterministic-hash mode, UUIDs on by default
a.register(value="cust_8f3k2", type="cust")   # alias any value, with a type prefix
a.register(pattern=r"order_\d+", type="ord")  # ...or a custom pattern

aliased = a.aliasify("user f47ac10b-58cc-4372-a567-0e02b2c3d479 placed order_991")
restored = a.restore(aliased)         # exact inverse; unknown aliases pass through

Single call

from langchain_id_aliaser import wrap_model

model = wrap_model(chat_model)        # alias in, restore out — incl. tool calls
model.invoke(messages)

Agent middleware

from langchain_id_aliaser import AliasMiddleware

agent = create_agent(model, tools, middleware=[AliasMiddleware()])

Raw graph

from langchain_id_aliaser import make_model_node

graph.add_node("model", make_model_node(chat_model))

Options

  • mode="hash" (default): deterministic alias from the id — same id → same alias, no stored state, stable across turns. mode="ordinal": id1, id2 … (shorter, but the mapping must be reused to stay consistent).
  • strict=True: raise UnknownAliasError when the model emits an alias-shaped token that isn't in the mapping. Default is forgiving (pass through).

License

MIT

Metadata

Release files for langchain-id-aliaser 0.1.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 langchain-id-aliaser 0.1.0
File Size Uploaded
langchain_id_aliaser-0.1.0.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-id-aliaser 0.1.0
File Interpreter ABI Platform
langchain_id_aliaser-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.9 kB

Release files / langchain_id_aliaser-0.1.0.tar.gz

Download URL langchain_id_aliaser-0.1.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d23a4cfd351a7f392b5fb6d20bd3d4bed67241711838ba99dc7119512b7d4c06
BLAKE2b-256 checksum
How to use checksums
6c4c1208d3a2523f40c5552583deb6cbff89e303fdb05c7138c886c27e57a63c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2026.

Transparency log

Release files / langchain_id_aliaser-0.1.0-py3-none-any.whl

Download URL langchain_id_aliaser-0.1.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d594f530e3d2209257e7ad4608b613b8ffa3b6250ea1aec772e9f660487747e2
BLAKE2b-256 checksum
How to use checksums
14ce6e65fb1f1053edeac7fba615b71f927d812af7f83a86fe1654e881063469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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