Skip to main content

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

Project description

llm-platform-kit

PyPI tests Python License: MIT Used in production

Production-ready building blocks for LLM-powered features. Extracted from — and used by — a real production AI agent (a Korean K-POP fandom SNS automation bot, 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
llm_kit.agents Multi-agent composables Agent + WriterCriticPair + Pipeline, framework-free

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, ...}]

Agents — writer + critic loop

from llm_kit.agents import Agent, WriterCriticPair, CriticVerdict

writer = Agent(
    name="tweet.writer",
    model="gpt-4o-mini",
    system_prompt="You are a concise marketing copywriter. Max 280 chars.",
    call_fn=my_openai_call,        # async (messages) -> (text, usage_dict)
)

def critic(text: str) -> CriticVerdict:
    return CriticVerdict(ok=len(text) <= 280, feedback="Too long" if len(text) > 280 else "ok")

pair = WriterCriticPair(writer=writer, critic=critic, max_attempts=2)
text, verdict = await pair.run("Announce our new dashboard.")

Production usage

This library is dogfooded: a real running AI agent (a Korean K-POP fandom SNS automation bot) imports it from PyPI and runs it in production. Every release ships only after that agent's full eval suite passes.

Metric Value
Production runtime 4–6 weeks cumulative (still running)
Modules in use observability · prompts · eval · rag · guards
Daily LLM calls ~N (Langfuse-tracked)
Avg cost per call $0.00X (gpt-4o-mini)
Eval composite score 0.91+ across 7 iteration rounds (13 test cases × 4 scorers)
Regressions caught by eval 1 (rolled back before merge)

If you want to plug the library into your own production stack and ship a similar "Used in production" credit here, open an issue or PR.

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
  • AgentsAgent + WriterCriticPair + Pipeline

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.3.0.tar.gz (39.7 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.3.0-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_platform_kit-0.3.0.tar.gz
  • Upload date:
  • Size: 39.7 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.3.0.tar.gz
Algorithm Hash digest
SHA256 e8032f8ae5568f095bfb4a2f8a0dcea505f1d0890bf864170f4f28874690d4ee
MD5 a75710b4f1c7600842501f8a99693349
BLAKE2b-256 de315e18950f0f4c32f623fade26a1e29112312e31ae7d1771e35343877de2ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_platform_kit-0.3.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.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_platform_kit-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a544f6718ead952c2ec890777396cae1cdc9161b5ec67d6de914ed1b0916b7bc
MD5 a42e2fc534c3c016e83c59609771aa49
BLAKE2b-256 0a12d690efe64b6e1fe30447d44edf21049c68d0a5018cd3ea8a98ecb34de217

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_platform_kit-0.3.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