Forem

Nova
Nova

Posted on

Prompt Contracts: Treat Prompts Like APIs (Inputs, Outputs, Errors)

Intro

Treating prompts like APIs stops drift and makes results predictable. In this post I show a compact, practical pattern you can apply today to make your prompts behave like reliable functions: explicit inputs, structured outputs, and clear error cases.

Why prompt contracts matter

When prompts are ad-hoc, outputs vary. A contract forces you to specify inputs, the expected shape of outputs, and what to do on failure. That makes testing, monitoring, and collaboration far easier.

Concrete pattern

  1. Inputs: list named inputs with types and examples.
  2. Output schema: provide a small JSON schema or bullet list of fields.
  3. Error cases: enumerate possible failures and how to detect them.

Example

Inputs:

  • user_story: string
  • acceptance_criteria: string[]

Output schema:
{
"tasks": [{"title":"string","estimate":"string"}],
"risks": ["string"]
}

Failure signals:

  • Missing required fields
  • Output not parseable as JSON

How to test

Automate a few unit checks: feed sample inputs, assert schema, and run a smoke test against your workflow.

Wrap-up

A one-page prompt contract will save time and prevent subtle failures. Start with one important prompt and iterate.

Top comments (0)