Tiny IDs for big language models. Maps UUIDs to short, category-prefixed aliases optimized for LLM context windows.
Project description
🦐 Shrimp
Shrimp your UUIDs. Tiny IDs for big language models.
Shrimp turns long, opaque IDs (UUIDs, hashes, DB keys) into short, category-prefixed aliases that LLMs can actually read, reason about, and reference back without hallucinating.
f47ac10b-58cc-4372-a567-0e02b2c3d479 → USR_001
8a3f9d2e-... → ORD_042
Why
Passing UUIDs to an LLM is wasteful and risky:
- Tokens. A UUID is ~13 tokens. Multiply by every row in every search result.
- Hallucination. LLMs flip characters in long opaque strings. One wrong hex char and you're pointing at nothing — or worse, the wrong row.
- Debuggability.
USR_003 messaged USR_007is readable. The UUID version is not.
Shrimp gives you a stable, scoped alias on the way in, and resolves it back on the way out.
Install
pip install shrimp
Quickstart
from shrimp import Shrimp
shrimp = Shrimp(redis_url="redis://localhost:6379")
# Encode
short = shrimp.encode("user", "f47ac10b-58cc-4372-a567-0e02b2c3d479")
# -> "USR_001"
# Decode
category, real_id = shrimp.decode("USR_001")
# -> ("user", "f47ac10b-58cc-4372-a567-0e02b2c3d479")
No Redis? Use the in-memory backend:
from shrimp import Shrimp
from shrimp.backends import MemoryBackend
shrimp = Shrimp(backend=MemoryBackend())
Render structured data
Walk a nested object and swap registered fields with short IDs before sending to the model:
data = {
"user_id": "f47ac10b-...",
"orders": [{"id": "8a3f...", "total": 50}],
}
rendered = shrimp.render(data, fields={
"user_id": "user",
"orders.[].id": "order",
})
# {"user_id": "USR_001", "orders": [{"id": "ORD_001", "total": 50}]}
Resolve LLM output
Catch hallucinated IDs and substitute real ones back:
result = shrimp.resolve(llm_response_text)
print(result.resolved) # text with real UUIDs restored
print(result.unknown_ids) # IDs the model made up
print(result.stats) # {"resolved": 4, "hallucinated": 1, "rate": 0.2}
Customize the scheme
from shrimp import Shrimp, Scheme
scheme = Scheme(
prefix_map={"user": "U", "order": "O"},
separator="-",
counter_format="{:04d}", # U-0001, U-0002
)
shrimp = Shrimp(redis_url="...", scheme=scheme)
Or take full control:
scheme = Scheme(aliaser=lambda category, n: f"{category[:3]}.{n:x}")
# user.1, user.2, ..., ord.a
Scopes
Mappings are scoped so different sessions or requests don't leak into each other:
with shrimp.scope("session_123") as s:
s.encode("user", uuid)
# Auto-expire after 1 hour
shrimp.create_scope("session_123", ttl_seconds=3600)
What Shrimp is not
- Not a vector store, not a memory system, not a prompt framework.
- Not a security boundary. Short IDs are scoped tokens, not auth.
- Not a general-purpose ID generator (use Sqids or ULID for that).
Status
Pre-release. APIs may shift before v1.0. Issues and PRs welcome.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shrimp_llm-0.1.0.tar.gz.
File metadata
- Download URL: shrimp_llm-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41f7b0e926833b4d3f11efb3318e0d7c58fba85127bab6cb15d266a5c7434b2e
|
|
| MD5 |
e017a75e3466736727fec72c0e6cb531
|
|
| BLAKE2b-256 |
02dfb24f599659961b3586bf31acc34bf47718b6e4ea85e9226b1851dd597477
|
File details
Details for the file shrimp_llm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shrimp_llm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a79a357fa1272cc03b1719976dab1e15b8513a6318e556feffa688e8808e99bf
|
|
| MD5 |
3942f69920f2879035d4dc51858e9e3b
|
|
| BLAKE2b-256 |
abf382bcd4f68621d35e1b6f23143e3c0ed29160394e571cb7532840e886203a
|