← metaobjects.dev

Prompt construction · AI-era drift

Prompts are code now, and OpenAI says so

On November 30, 2026, OpenAI is shutting down its managed Prompts API. Their migration guide tells customers what to do instead:

A year earlier, Humanloop, one of the most engineering-minded prompt platforms, shut down after its team joined Anthropic.

The first generation of prompt management treated prompts like CMS content: strings stored in someone else's cloud, edited in a dashboard and fetched at runtime. Its biggest backer is now walking away from that, and what it recommends instead (typed inputs, version control, build-time checks, cache-stable rendering) is how we already handle code.

We already learned this lesson once

Twenty years ago, SQL scattered through string concatenation gave us injection bugs and data access that was hard to refactor, so we moved queries behind typed interfaces. Configuration scattered through environments gave us "works on my machine", so we moved it into declarative, versioned files.

Prompts are at the same point now, with one difference the earlier shifts didn't have: AI now writes much of your code. Every regeneration is a chance for your prompts to quietly disagree with the model they describe, through a renamed field, a changed enum or a restructured payload. A prompt that drifts doesn't throw an exception. It gets worse in production, and nothing reports it.

Treating a prompt as code takes four things:

  1. Typed inputs. The prompt's variables come from a declared, typed structure, not ad-hoc string substitution.
  2. Build-time verification. Rename a field the prompt uses, and the build fails.
  3. Deterministic rendering. The same inputs produce byte-identical prompt text, which your snapshot tests and your prompt cache both depend on.
  4. Typed output handling. The response contract is declared once, and parsing (including recovering from the malformed output real models produce) is generated from it.

Almost no current tool does these.

The prompt platforms don't type your variables

I went through the docs of every major prompt-management platform: Langfuse, LangSmith, PromptLayer, Agenta, Braintrust. They are good at what they were built for: versioned templates, deployment labels, A/B testing, dashboards and non-engineer editing.

But on the four requirements above:

And the typed-extraction tools (Instructor, Outlines, Pydantic-AI, LangChain's structured output, TypeChat, BAML) own the output half of the problem, and do it well. But across all of them, only BAML has a cross-language schema (and no native Java, Kotlin or C#). Repairs are either silent (BAML's SAP), bought with another LLM call (everyone's retry loops), or delegated to vendor-locked constrained decoding. No tool in the field produces a recovery report telling you what it fixed, no tool repairs XML, and none of them connect the prompt's schema to the rest of your application — the database column, the API field, the UI form that hold the same data.

That last gap matters most, because prompt drift is almost never a prompt-only event. The field was renamed in the domain model, and the prompt was the surface nobody checked.

What prompts-as-code looks like in practice

MetaObjects was built around this problem. It is an open-source (Apache 2.0) metadata standard: you declare your data model once, in plain YAML in your repo, and it generates idiomatic code in TypeScript, C#, Java, Kotlin, and Python — entities, schema, API routes, and prompts, all from the same model.

(It grew out of a mess of my own: a few thousand lines of StringBuilder driving the characters in an LLM game. The longer essay, The prompt is code, and yours is drifting too, covers the origin story and the data + text + render split that became the fix.)

A prompt declares its input as a typed payload, a value object whose members bind to the same entities that drive your database and API, so the prompt's shape is part of the model rather than a lookalike beside it. It names its text by a logical reference, so the text stays a versioned file in your repo rather than a row in someone's cloud:

# Bound to Subscriber's fields — a projection, not a copy.
- object.value:
    name: SubscriberBlurbPayload
    children:
      - field.string: { name: name, extends: Subscriber.name }
      - field.enum:   { name: status, extends: Subscriber.status }

- template.prompt:
    name: subscriberBlurb
    payloadRef: SubscriberBlurbPayload
    textRef: subscriber/blurb

Naming the members is what makes a prompt's cost visible. Fill a template from an untyped bag and the answer to “what do we send this model?” is whatever the caller had lying around. Someone passes the whole user object because it was in scope, thirty fields ride along on every call forever, and nothing records that it happened. When the payload is declared, adding a field to a prompt is a line in a pull request, with a name on it, in a review, next to the reason. Payload bloat shows up as a diff you approve or reject, not as a mystery you diagnose from a bill.

From that one declaration you get a generated, typed render function per language, deterministic and byte-identical across all five ports (a shared conformance corpus checks it), so snapshot tests pass and your exact-prefix prompt cache stays warm. Nothing reformats your prompt behind your back.

The cache is worth spelling out, because a broken one has no symptom. Provider prompt caching matches your prompt from the first byte, and the first byte that differs ends the match — everything after it is billed as new input, where a hit would have cost up to about a tenth as much. So a reordered key, a trailing space, or a template helper that starts pretty-printing does not throw, does not return a worse answer, and does not show up in a log or a test. It shows up on the invoice four weeks later, as a number nobody can attribute to a change. Deterministic rendering rules out that class of bug.

Because the payload is declared, the build can check it. Rename Subscriber.name and the payload above cannot be left behind: extends: Subscriber.name stops resolving, so the rename is forced into it. What is not forced is the template still writing the old variable, and nothing else was watching that. meta verify says so and exits non-zero:

meta verify — requirements: 1 entries (1 functional, 0 architectural) — 1 live; 1/1 entities claimed, counted over 1 metadata file(s).
meta verify — not run: schema (--db <url>), codegen (--codegen), deps (--deps), replay (--replay)
meta: [subscriberBlurb] (prompt) ERR_VAR_NOT_ON_PAYLOAD: name (templates/subscriber/blurb.mustache:1)
meta: meta verify — 1 drift error(s) across 1 template(s).

At that point a prompt stops being a string and becomes code: the renamed field is a build error, not a quality regression you discover three weeks later.

The output side is declared the same way, and one declaration drives three generated artifacts: the output-format instructions injected into the prompt, a strict typed parser, and a tolerant extractor for the output real models produce: prose wrappers, code fences, unclosed XML tags, off-vocabulary enum values. It returns best-effort typed data plus a structured recovery report of what was repaired and what was lost, and it never throws. It handles JSON and XML; XML matters because a missing close tag is locally repairable, while a missing JSON brace corrupts everything after it.

The traces are typed too: LLM calls persist into your own database with the request and response as typed value objects (the same declared payload) instead of opaque JSON blobs. (And if you like your Langfuse dashboards, keep them: the recorder exports to Langfuse and OpenTelemetry while the typed copy lands in your DB.)

You don't have to replace your stack to do this

You can adopt this alongside what you already run:

This is the same move SQL and configuration made: a prompt's inputs and outputs become part of your type system, your build and your version control. Once AI writes half the code, keeping the pieces in agreement is the hard part, and noticing problems in a dashboard after the fact doesn't do that. OpenAI is now telling its customers the same thing.

MetaObjects is Apache-2.0 open source, installable today in five languages. npm i @metaobjectsdev/cli  ·  pip install metaobjects  ·  dotnet add package MetaObjects  ·  Maven Central Start at metaobjects.dev or read the spec.