Skip to main content

Production-ready LLM platform building blocks — observability, prompts, eval, RAG, hallucination guards

Project description

llm-platform-kit

Production-ready building blocks for LLM-powered features. Extracted from a real production AI agent (a K-POP fandom SNS automation bot, running for 4–6 weeks of cumulative operation) — only the domain-neutral patterns are kept here.

Who is this for? Teams shipping LLM features (chat, search, summarization, recommendation, auto-reply) inside a real product.

What's inside

Module Pattern One-liner
llm_kit.observability LLM call tracing Langfuse drop-in + manual generation helper
llm_kit.prompts Externalized prompts + hot-swap Decouple prompt files from code; edit in place
llm_kit.eval Test set + auto-scoring YAML eval set × 4 scorers (rule + LLM judge)
llm_kit.rag Semantic search (Chroma + embedding) OpenAI embedding + local Chroma file
llm_kit.guards 6-layer hallucination defense regex + retry + LLM judge integration

Each module is independently usable. Dependencies are also split (pip install llm-platform-kit[observability]).

Why this exists

Anyone who has shipped an LLM feature to production has needed roughly the same setup, every time:

  1. How much did that call cost / how slow was it / did the model hallucinate? → observability
  2. Tweak a prompt without redeploying the whole service → externalization + hot-swap
  3. Did this change break any of my previous answers? → eval framework
  4. Search my own data by meaning, not exact keywords → RAG
  5. Stop the model from making things up → hallucination guards

Larger frameworks (LangChain / LangGraph) cover all of this, but bring heavy opinions and a steep learning curve. This library keeps each pattern as a small (100–300 LOC) module you can drop into your existing stack.

Quick start

pip install llm-platform-kit[all]

Observability — trace OpenAI calls in 3 lines

import os
from openai import AsyncOpenAI
from llm_kit.observability import trace_generation

os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."

client = AsyncOpenAI()
resp = await client.chat.completions.create(...)

trace_generation(
    name="my_feature.draft",
    model="gpt-4o-mini",
    input=messages,
    output=resp.choices[0].message.content,
    usage=resp.usage.model_dump(),
)

Prompts — externalize

# brain/prompts/customer_support.md lives outside the code repo
from llm_kit.prompts import read_text

system = read_text("prompts", "customer_support.md")
# Edit the file in production → the next call picks up the change.

Eval — assertion-style scoring

# evals/customer_support.yaml
dataset_name: "cs_v1"
items:
  - id: ev_refund_policy
    query: "Tell me about your refund policy."
    expected_tools: [search_kb]
    forbidden_phrases: ["I'm sorry, I don't know"]
    judge_criteria: "Must mention refund-eligible conditions + time window."
    max_chars: 500
from llm_kit.eval import run_eval

async def my_agent(query: str) -> dict:
    # ... your agent call ...
    return {"text": response, "tools_called": [...]}

summary = await run_eval("evals/customer_support.yaml", agent_fn=my_agent)
print(summary["scores"])  # {'length': 1.0, 'hallucination': 1.0, ...}

RAG — semantic search

from llm_kit.rag import RAGCollection

rag = RAGCollection("knowledge_base")
await rag.upsert(
    ids=["doc1", "doc2"],
    texts=["Refund policy ...", "Payment methods ..."],
    metadatas=[{"source": "policy"}, {"source": "policy"}],
)

hits = await rag.search("how do I get my money back?", top_k=3)
# → [{"text": "Refund policy ...", "similarity": 0.82, ...}]

Real-world track record

Metric Value
Production runtime 4–6 weeks cumulative (and counting)
Daily LLM calls ~N
Avg cost per call $0.00X (gpt-4o-mini)
Eval composite score 0.94 / 1.0 (13 test cases × 4 scorers)
Iteration tracking 7 rounds, 1 regression caught & rolled back

Design principles

  1. Each module stands alone — adopt just one if that's what you need
  2. Minimal hard dependencies — no framework lock-in
  3. No silent fallbacks — missing config → fail fast (no debugging a happy path that's actually broken)
  4. Production-tested — every design choice is the result of an actual incident in operation

Per-module docs

  • Observability — Langfuse integration + manual trace
  • Prompts — externalization + hot-swap + fail-fast
  • Eval — 4 scorers + CI integration
  • RAG — Chroma + embedding pipeline
  • Guards — 6-layer hallucination defense

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_platform_kit-0.2.0.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_platform_kit-0.2.0-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file llm_platform_kit-0.2.0.tar.gz.

File metadata

  • Download URL: llm_platform_kit-0.2.0.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for llm_platform_kit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cc0d6aa548f570b057055dc478d7fe39ea001a89773b3cec5c4f4f4bb6e2677b
MD5 a5d34b62d16b09b5f012feae36829b01
BLAKE2b-256 72e0ba792fc528789d9d559e728800ef672c7f9244c390392b362b38496898d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_platform_kit-0.2.0.tar.gz:

Publisher: publish.yml on manjees/llm-platform-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_platform_kit-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_platform_kit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13aa48fdf443bff84a0324381136d8c1a2aae54d7ad1929bf02f780cecda89aa
MD5 52946eb84e28788881aa580ec72de4e9
BLAKE2b-256 2138a7c50aed498cea534fcc24fdfc2328416596437e2e750753b4dd6df34696

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_platform_kit-0.2.0-py3-none-any.whl:

Publisher: publish.yml on manjees/llm-platform-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page