Skip to main content

🦐 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_007 is 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

Metadata

Release files for shrimp-llm 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 shrimp-llm 0.1.0
File Size Uploaded
shrimp_llm-0.1.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shrimp-llm 0.1.0
File Interpreter ABI Platform
shrimp_llm-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / shrimp_llm-0.1.0.tar.gz

Download URL shrimp_llm-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
41f7b0e926833b4d3f11efb3318e0d7c58fba85127bab6cb15d266a5c7434b2e
BLAKE2b-256 checksum
How to use checksums
02dfb24f599659961b3586bf31acc34bf47718b6e4ea85e9226b1851dd597477
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

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

Download URL shrimp_llm-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a79a357fa1272cc03b1719976dab1e15b8513a6318e556feffa688e8808e99bf
BLAKE2b-256 checksum
How to use checksums
abf382bcd4f68621d35e1b6f23143e3c0ed29160394e571cb7532840e886203a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

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