惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
T
Tenable Blog
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
T
The Exploit Database - CXSecurity.com
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
H
Help Net Security
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
S
Schneier on Security
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
P
Privacy International News Feed
S
Secure Thoughts
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
C
Cybersecurity and Infrastructure Security Agency CISA
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
博客园 - Franky
T
Tor Project blog
G
GRAHAM CLULEY
博客园 - 【当耐特】
Jina AI
Jina AI
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
A
About on SuperTechFans
Hacker News - Newest:
Hacker News - Newest: "LLM"

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Your LLM Prompts Are Running Ungoverned in Production. Here's the Architecture Fix.
Jachin Saikia Sonowal · 2026-06-27 · via DEV Community

I want to show you something embarrassing.

This is an actual git commit from my codebase, January 2025:

commit a3f91c2
Author: Gandiv <gandiv@----.io>
Date:   Fri Jan 10 23:41:07 2025

    update assistant tone

diff --git a/config/prompts.py b/config/prompts.py
@@ -12,7 +12,7 @@
-SYSTEM_PROMPT = "You are a professional assistant. Respond formally and thoroughly."
+SYSTEM_PROMPT = "You are a helpful assistant. Be direct and concise."

That commit went to production. No review. No diff visible to anyone except me. No record of what the previous behaviour was or why I changed it. No rollback plan. Just me, 11:30 pm, editing a string and hoping nothing breaks.

Three weeks later, a different engineer on the team "cleaned up" the config file and reverted that change. Neither of us noticed for six days. Users noticed on day two.

That six-day gap between "prompt regressed" and "we found it" is what I built PromptMatrix to eliminate.

The Infrastructure Gap Nobody Talks About

Here's the thing about prompts that makes them different from every other config value in your stack.

A database connection string either works or it doesn't. The failure mode is binary and immediate.

A prompt failure is behavioural and gradual. The AI still responds. It just responds slightly differently — softer tone, different refusal behaviour, subtly broken persona — and you find out from user feedback three days later, not from a monitoring alert three seconds later.

This asymmetry means the standard config management approach (environment variables, hardcoded strings, .env files) is genuinely wrong for prompts. You're using a tool designed for binary failure modes on something with subtle behavioural failure modes.

What you actually need is what we already have for code: version history, diff visibility, review gates, and rollback capability.

The problem is nobody built that for prompts. Until recently.

What the Current State Looks Like

Before I get into the architecture, let me be honest about what "prompt management" looks like at most teams building LLM products right now.

Stage 1: The string in the file

# agent.py
SYSTEM_PROMPT = "You are a customer support agent for Acme Corp. Be helpful and professional."

response = client.messages.create(
    model="claude-sonnet-4-6",
    system=SYSTEM_PROMPT,
    messages=[{"role": "user", "content": user_message}]
)

This is where everyone starts. It's fine for a prototype. It becomes a liability the moment anyone other than you needs to change that string.

Stage 2: The environment variable

# agent.py
import os

SYSTEM_PROMPT = os.getenv("SYSTEM_PROMPT", "You are a helpful assistant.")

Slightly better. Now you can change the prompt without touching code. But you still need a deploy to push the new value. And you have zero history of what the value was before.

Stage 3: The database config table

# agent.py
from db import get_config

SYSTEM_PROMPT = get_config("system_prompt")

Now changes can happen without a redeploy. But there's still no diff view, no approval workflow, no audit trail, and no interface a non-engineer can safely use.

Stage 4: The Notion doc

This is where the organizational debt starts compounding. Someone creates a Notion page called "Approved Prompts - Production." Engineers are supposed to copy from there. They don't always. The doc diverges from production. Nobody knows which version is actually running.

Sound familiar? It should. Almost every AI product team I've talked to is somewhere between stages 2 and 4.

What Production Prompt Governance Actually Requires

Let me spec this out properly, because I think the requirements are underappreciated.

Requirement 1: A canonical registry with stable keys

Every prompt needs a stable identifier — not a variable name that can be renamed in a refactor, but an immutable key that becomes part of your API contract.

assistant.system
email.rewriter  
lead.qualifier
data.extractor

These keys are how your application references prompts. The content behind them can change; the key never does.

Requirement 2: Immutable version history

Every time a prompt changes, the previous state must be preserved. Not in a git log (which requires repository access to read), but in a queryable history that shows you: what changed, who changed it, when, and what the diff was.

Requirement 3: A review gate between proposal and production

This is the one most teams skip, and it's the most important one.

The workflow should be:

Someone proposes a change (can be anyone with dashboard access)
A designated reviewer sees the diff — old content vs new, line by line
The reviewer approves or rejects with a note
On approval: new content becomes live, previous version is archived

This gate is what makes it safe to give non-engineers editing access. Without it, giving a PM access to prompt storage is terrifying. With it, it's exactly what you want.

Requirement 4: Runtime serving, not build-time bundling

Your application should fetch the current approved prompt at runtime, not read it from a config file at build time.

# Before: build-time, requires redeploy to change
SYSTEM_PROMPT = "You are a helpful assistant..."

# After: runtime fetch, changes go live on next request
SYSTEM_PROMPT = pm.serve("assistant.system")

When a prompt change is approved, the very next call to pm.serve() returns the new content. No restart. No redeploy. No cache flush (the SDK handles TTL internally).

Requirement 5: An audit trail that survives debugging sessions

When something breaks, you want to be able to answer: "what prompt was this agent running at 14:23 on Tuesday?" in under five minutes.

That requires an append-only log of every state change — who proposed, who approved, what the before and after content was, exact timestamps.

The Architecture

Here's how PromptMatrix implements these requirements.

The Data Model

At the core, there are three entities that matter:

Prompt
  id: UUID
  environment_id: UUID  
  key: VARCHAR(200)           -- e.g. "assistant.system"
  live_version_id: UUID       -- FK to current approved PromptVersion

PromptVersion  
  id: UUID
  prompt_id: UUID
  version_num: INT            -- monotonically increasing per prompt
  content: TEXT               -- the actual prompt string
  parent_content: TEXT        -- previous live content, stored for diff
  status: ENUM                -- draft | pending_review | approved | archived
  proposed_by_id: UUID
  approved_by_id: UUID
  commit_message: VARCHAR(500)
  created_at: TIMESTAMPTZ

AuditLog
  id: UUID
  action: VARCHAR(100)        -- "version.approved", "version.rollback", etc.
  resource_id: VARCHAR(100)
  actor_email: VARCHAR(255)
  extra: JSONB                -- diff, notes, override flags
  integrity_hash: VARCHAR(64) -- SHA-256 of action + resource + extra
  created_at: TIMESTAMPTZ     -- append-only, no UPDATE/DELETE ever

The parent_content field on PromptVersion is the key architectural decision. By storing the previous live content at the moment a new version is created, you get diffs for free without needing to query across version pairs.

The State Machine

draft ──[submit]──────────────► pending_review
                                      │
                              [approve / reject]
                                  │         │
                               approved   rejected
                                  │
                         [new version created]
                                  │
                               archived

In development mode, there's a quick-approve shortcut: draft → approved in one step, skipping the review queue. This is gated to APP_ENV=development only — it 403s in production.

The Hot Path: The Serve Endpoint

This is the part where latency actually matters, because it's in your LLM call path.

GET /pm/serve/assistant.system
Authorization: Bearer pm_live_xxxxxxxxxxxxx

# 1. Extract and hash the API key
raw_key = request.headers["Authorization"].split(" ")[1]
key_hash = sha256(raw_key)

# 2. Check in-memory cache for key metadata
key_data = cache.get(f"key:{key_hash}")
if not key_data:
    key_data = db.query(ApiKey).filter_by(key_hash=key_hash).first()
    cache.set(f"key:{key_hash}", key_data, ttl=300)

# 3. Rate limit check (in-memory window counter)
check_rate_limit(key_hash, key_data["plan_rpm"])

# 4. Fetch prompt content (cache-first)
cache_key = f"prompt:{key_data['env_id']}:assistant.system"
content = cache.get(cache_key)
if not content:
    prompt = db.query(Prompt).filter_by(
        environment_id=key_data["env_id"],
        key="assistant.system"
    ).options(joinedload(Prompt.live_version)).first()
    content = prompt.live_version.content
    cache.set(cache_key, content, ttl=30)

# 5. Variable substitution
content = substitute_variables(content, request.query_params)

# 6. Return
return PlainTextResponse(content, headers={
    "X-PM-Version": str(prompt.live_version.version_num),
    "X-PM-Cache": "HIT" if cache_hit else "MISS",
    "X-PM-Latency": f"{latency_ms}ms"
})

Cache hit path: ~5ms. Cache miss path (DB query): ~50ms. The cache TTL is 30 seconds by default, so the maximum lag between "approved" and "live" is 30 seconds.

The cache is a pure-Python LRU dict in local mode. In cloud mode (Vercel serverless), it's Upstash Redis via REST API — because in-memory state doesn't survive serverless cold starts.

Variable Substitution

Prompts can have dynamic variables using {{double_curly}} syntax:

You are a support agent for {{company_name}}. 
Respond in {{tone}} tone. Escalate billing issues to tier {{escalation_tier}}.

These get substituted at serve time via query params:

GET /pm/serve/support.agent?vars=company_name=Acme&vars=tone=professional&vars=escalation_tier=2

The parser uses repeated vars params (not comma-delimited) to avoid breaking on values that contain commas:

var_dict = {}
for v in request.query_params.getlist("vars"):
    if "=" in v:
        k, val = v.split("=", 1)
        if re.match(r'^[\w_]+$', k.strip()):
            var_dict[k.strip()] = val.strip()

content = re.sub(
    r'\{\{([\w_]+)\}\}',
    lambda m: var_dict.get(m.group(1), m.group(0)),
    content
)

Unfilled variables are left as {{variable_name}} and reported in the JSON response's unfilled_variables field. This lets you catch misconfigured agent calls before they silently pass empty values to your LLM.

SDK Usage

# pip install promptmatrix-sdk

from promptmatrix import PromptMatrix

pm = PromptMatrix(api_key="pm_live_xxxxxxxxxxxxx")

# Basic fetch — cached locally for 30s
system_prompt = pm.serve("assistant.system")

# With variables
system_prompt = pm.serve(
    "support.agent",
    variables={
        "company_name": "Acme",
        "tone": "professional"
    }
)

# Async
system_prompt = await pm.aserve("assistant.system")

# With fallback — if endpoint unreachable, use this string
system_prompt = pm.serve(
    "assistant.system",
    fallback="You are a helpful assistant."
)

The SDK handles local TTL caching, so you're not making an HTTP call on every LLM request. The cache invalidates automatically when the TTL expires — you'll pick up any approved changes within 30 seconds.

The Eval Engine

One thing worth calling out separately: before a prompt change gets approved, you can run it through an evaluation pipeline.

Rule-based eval (zero dependencies, <5ms):

Scores the prompt across 8 dimensions:

Dimension: What it checks. Role clarity. Does it open with a clear persona definition? Instruction quality: Are commands imperative and unambiguous?Output format: Is the expected output structure specified? Specificity: Are there concrete constraints or examples? Variable usage: Are dynamic values parameterised as {{vars}}? Context provision: Is sufficient background provided?Length: Is it in the 50-800-word optimal range?Safety: No PII patterns, no hardcoded secrets, no injection vectors?

LLM-as-judge eval (BYOK — your API key, never stored):

Sends the prompt to a judge model (Claude, GPT-4o, Gemini, Groq, or Mistral) with a structured rubric. Returns per-criterion scores and specific suggestions. The key material is injected into the request payload and deleted from Python scope immediately after — it never touches the database or logs.

You can configure environments to require a minimum eval score before an approval can go through:

# environment config
eval_required = True
eval_pass_threshold = 7.0  # out of 10

# in approve_version():
if env.eval_required and env.is_protected:
    if version.last_eval_score is None:
        raise HTTPException(422, "Eval required before approval in this environment")
    if version.last_eval_score < env.eval_pass_threshold:
        if not body.override_eval:
            raise HTTPException(422, f"Score {version.last_eval_score} below threshold")
        require_role(member, "admin")  # only admins can override

Anti-Patterns Worth Avoiding

A few things I got wrong early that cost me debugging time:

Don't use joinedload for version lists

# This loads ALL version content for ALL prompts. OOM risk at scale.
prompts = db.query(Prompt).options(joinedload(Prompt.versions)).all()

# Do this instead — load live version only, count others via subquery
from sqlalchemy import func
versions_count = db.query(
    PromptVersion.prompt_id,
    func.count(PromptVersion.id).label("count")
).group_by(PromptVersion.prompt_id).subquery()

Don't name a SQLAlchemy column metadata

Metadata is a reserved attribute on DeclarativeBase. It will silently override the ORM's own metadata object. Name it extra, meta, or data.

Don't pass pool_size to SQLite

# This raises TypeError with SQLite
engine = create_engine(DATABASE_URL, pool_size=5)

# Gate it
is_sqlite = DATABASE_URL.startswith("sqlite")
kwargs = {} if is_sqlite else {"pool_size": 2, "max_overflow": 5}
engine = create_engine(DATABASE_URL, **kwargs)

Don't store LLM API keys in the database

Even encrypted. Use them in request and delete from scope immediately. If you need to save team keys, AES-256-GCM with key material from an env var only — and generate a fresh 12-byte nonce per encryption, never reuse it.

git clone https://github.com/PromptMatrix/promptmatrix.github.io
cd promptmatrix
./start.sh

start.sh creates a venv, installs dependencies, generates JWT_SECRET_KEY and ENCRYPTION_KEY, runs Alembic migrations, seeds a local admin user, and starts uvicorn on port 8000.

Open http://localhost:8000/dashboard — no login screen in development mode. The dashboard connects directly via the dev bypass, which is gated to APP_ENV=development.

The Broader Point

The engineering discipline around prompt management is about two years behind the engineering discipline around application code. We're still in the "put it in an env var" phase, and we need to get to the "versioned, reviewed, audited, rollback-capable" phase.

This isn't a tooling problem primarily. It's a mental model problem. Prompts aren't config values — they're behavioural specifications. They deserve the same rigour we give to the code that runs on top of them.

The architecture I've described here — stable key registry, immutable version history, review gate, runtime serving, audit trail — you can build this yourself in a weekend. Or you can use PromptMatrix, which is MIT licensed and runs locally for free.

Either way, the right answer is not to leave your AI behaviour running ungoverned in a Python dictionary.

PromptMatrix is open source. GitHub: github.com/PromptMatrix/promptmatrix.github.io

Cloud version with team RBAC and LLM eval gating: promptmatrix.github.io

Questions about the architecture, the SQLAlchemy patterns, or the cache design — drop them in the comments. I read everything.