Prompt Templates for Developers: JSON, Extraction, Summarization, and Code Tasks
prompt-engineeringprompt-libraryjsondeveloper-workflows

Prompt Templates for Developers: JSON, Extraction, Summarization, and Code Tasks

UUCAFS Editorial Team
2026-11-29
8 min read

Reusable prompt templates for developers covering JSON, extraction, summaries, classification, code generation, and safe failure handling.

This reusable prompt library gives developers practical starting points for JSON generation, information extraction, summarization, classification, code tasks, and refusal handling. Each template includes placeholders, an output contract, an example, and checks for the failure modes that commonly appear in production LLM apps.

Overview

A prompt is not a complete application contract, but it is an important part of one. A reliable prompt tells the model what role it has, what input it may use, what operation to perform, what format to return, and what to do when the input is incomplete or outside scope.

Use the templates below as versioned starting points rather than copy-and-paste guarantees. Replace the bracketed values, test the prompt against representative inputs, and validate the response in application code. Structured output features, tool schemas, and model-specific instructions can change over time, so your integration should not rely on the prompt alone to enforce a data type or permission boundary.

A useful baseline prompt has five parts:

  1. Task: the operation the model must perform.
  2. Context: relevant information and its boundaries.
  3. Rules: constraints, definitions, and edge-case behavior.
  4. Output contract: the required fields, types, and format.
  5. Input: the variable content supplied at runtime.

Keep stable instructions separate from user-provided data. Delimit runtime content clearly, especially when processing documents that may contain instructions intended for another system. For sensitive workflows, consider redaction before model processing; see this guide to PII redaction for a dedicated workflow.

Checklist by scenario

1. JSON generation

Use this pattern when an application needs predictable fields rather than a conversational answer.

You are a data transformation component.

Task: Convert the input into the specified JSON object.

Output schema:
{
  "title": "string",
  "priority": "low | medium | high",
  "actions": ["string"],
  "unknowns": ["string"]
}

Rules:
- Return one valid JSON object and no surrounding commentary.
- Use only values supported by the input.
- If a field cannot be determined, use an empty array or null as specified.
- Do not add fields that are not in the schema.

Input:
---
[INPUT_TEXT]
---

Example input: “The billing export is late. Please check the connection today and ask Morgan to confirm the delivery date.”

Expected shape: The result should contain a high or medium priority selected according to your defined criteria, actions such as checking the connection and confirming the delivery date, and no invented deadline.

Double-check: Use application-side JSON parsing, schema validation, and a clear policy for missing values. If your provider supports native structured outputs, define the schema there as well as in the prompt.

2. Information extraction

Extraction prompts should define what counts as evidence and what happens when several candidates appear.

Extract the requested fields from the document below.

Fields:
- customer_name: exact name, or null
- invoice_id: exact identifier, or null
- due_date: date exactly as written, or null
- total_amount: numeric amount and currency, or null

Rules:
- Do not infer missing values.
- Preserve the source spelling for names and identifiers.
- If multiple values are present, select the one associated with the requested document; otherwise list the ambiguity in "notes".
- Include a short evidence quote for every non-null field.

Return JSON:
{
  "customer_name": null,
  "invoice_id": null,
  "due_date": null,
  "total_amount": null,
  "evidence": [],
  "notes": []
}

Document:
---
[DOCUMENT_TEXT]
---

For scanned or poorly formatted documents, treat extraction as a candidate-generation step. Validate identifiers, dates, and amounts with deterministic rules where possible. Do not let a plausible-looking value silently replace a missing value.

3. Summarization

A generic request to “summarize this” leaves length, audience, and priorities undefined. Add each explicitly.

You summarize technical documents for [AUDIENCE].

Create a summary of [MAX_WORDS] words using only the source below.

Include:
1. The main decision or purpose.
2. The most important facts or changes.
3. Risks, dependencies, or unresolved questions.
4. Recommended next steps only when the source states them.

Do not:
- Invent background information.
- Present a recommendation as a fact.
- Omit a material limitation merely to make the summary shorter.

Format:
- Overview: one paragraph
- Key points: 3 to 5 bullets
- Open questions: bullets, or "None stated"

Source:
---
[SOURCE_TEXT]
---

For long documents, decide whether to summarize sections independently and then summarize those summaries. Watch for duplicated points and lost qualifications. For streaming user interfaces, define how partial summaries are displayed and what happens if generation stops early; the LLM streaming guide covers tokens, events, errors, and UI state.

4. Classification

Classification prompts work best when labels have mutually understandable definitions and examples are not contradictory.

Classify the message into exactly one label.

Labels:
- billing: charges, invoices, refunds, or payment status
- technical: product behavior, errors, integrations, or access problems
- account: profile, membership, or credential changes
- other: none of the above or insufficient information

Rules:
- Choose the narrowest supported label.
- Do not classify based on sentiment alone.
- If two labels are plausible, choose the primary requested action and explain the ambiguity.

Return JSON:
{
  "label": "billing | technical | account | other",
  "confidence": "high | medium | low",
  "reason": "one sentence grounded in the message"
}

Message:
---
[MESSAGE]
---

Before deployment, test near-boundary examples, empty messages, mixed-intent messages, and adversarial wording. If the classification controls routing or access, use the result as one signal in a broader validation flow.

5. Code generation

Code-generation prompts should specify the environment, interfaces, constraints, and verification expectations. They should not imply that generated code is safe merely because it compiles.

You are generating code for [LANGUAGE_VERSION] in [PROJECT_CONTEXT].

Task: Implement [FUNCTION_OR_CHANGE].

Requirements:
- Preserve the existing public interface unless explicitly instructed otherwise.
- Handle [ERROR_CASES].
- Do not add dependencies.
- Follow the style shown in [REFERENCE_FILE_OR_SNIPPET].
- Explain assumptions before the code if required information is missing.

Return:
1. A short implementation note.
2. The complete changed code in one fenced block.
3. Tests covering [TEST_CASES].
4. A short list of risks or unverified assumptions.

Repository context:
---
[RELEVANT_FILES]
---

Limit the supplied repository context to files relevant to the task. Ask for a patch or diff when reviewability matters. Pair generated code with compilation, unit tests, security checks, and human review. For pull-request workflows, compare this approach with the practices in the AI code review workflow guide.

6. Refusal and uncertainty handling

Every production prompt needs a defined response for unsupported, unsafe, or incomplete requests. A useful refusal is specific without exposing hidden system instructions.

Perform the task only when it is within the supported scope: [SUPPORTED_SCOPE].

If the request is outside scope, unsafe, or lacks required information:
- Do not guess or fabricate an answer.
- Return the status "cannot_complete".
- Give one brief reason.
- Ask for the minimum safe clarification when clarification could resolve the issue.

Return JSON:
{
  "status": "complete | needs_clarification | cannot_complete",
  "result": null,
  "reason": null,
  "next_step": null
}

Request:
---
[REQUEST]
---

Keep refusal behavior aligned with your product requirements and provider capabilities. Test prompt injection, conflicting instructions, missing permissions, and requests for data the application should not expose.

What to double-check

  • Schema: Are field names, types, allowed values, and null behavior unambiguous?
  • Evidence: Does the prompt distinguish quoted facts from model inference?
  • Boundaries: Is user content clearly delimited from developer instructions?
  • Length: Is there a practical output limit, and does it fit the model and application token budget?
  • Failures: What should happen on empty input, conflicting input, malformed input, or a provider error?
  • Validation: Does application code parse, validate, sanitize, and log the response appropriately?
  • Observability: Can you identify the prompt version, model, input category, latency, error type, and output quality?
  • Permissions: If the model can call tools, are arguments validated and authorization checked outside the model?

For tool-enabled workflows, a prompt should describe when a tool is appropriate, but the tool schema and server-side permission checks remain authoritative. Review tool-calling patterns before connecting a prompt to actions with side effects.

Finally, create a small evaluation set before changing a production prompt. Include normal cases, edge cases, known failures, and examples where the correct response is uncertainty. Record expected properties rather than requiring every answer to match one exact string. A repeatable test suite makes output drift easier to detect; see the LLM evaluation framework comparison for evaluation planning.

Common mistakes

  1. Relying on “be accurate.” Accuracy improves when the task, evidence, labels, and failure behavior are concrete.
  2. Requesting JSON without a schema. State required fields, types, allowed values, and whether extra fields are forbidden.
  3. Mixing instructions with untrusted content. Delimit documents and messages, and tell the model to treat them as data.
  4. Using examples that conflict with the rules. Review few-shot examples for consistent labels, formatting, and edge-case behavior.
  5. Putting validation in the prompt only. Parse and validate every response in application code.
  6. Ignoring cost and latency. Remove unnecessary context, cap output length, cache stable work where appropriate, and choose a model based on tested requirements. The LLM cost optimization guide provides a broader checklist.
  7. Changing several variables at once. Version prompts and compare one meaningful change against a fixed evaluation set.
  8. Treating confidence as truth. A model-generated confidence label is not a calibrated probability unless you have tested it for that purpose.

When to revisit

Revisit this prompt library whenever you start a new LLM feature, move a workflow to another model, change the input source, add tools, or observe output drift. It is also useful before seasonal planning cycles, when workflows or tools change, or when a team is standardizing prompts across services.

At each review, run the same evaluation set and add any newly observed failure to it. Check model-specific structured-output guidance, context limits, token budgets, provider error behavior, and safety requirements rather than assuming that an old prompt behaves identically after a model update. Review a prompt more urgently when it extracts regulated or sensitive data, triggers an external action, affects user access, or produces code that enters a delivery pipeline.

A practical maintenance routine is:

  1. Assign a version to the prompt and record its intended task.
  2. Keep representative inputs and expected properties in a test set.
  3. Compare the current version with the proposed version on normal and failure cases.
  4. Inspect parsing errors, refusals, latency, token use, and human-review feedback.
  5. Roll out changes gradually when the workflow has meaningful operational impact.
  6. Document the model, schema, assumptions, and known limitations beside the prompt.

Start with one template, one narrow task, and a small test set. Once the output contract is stable, move enforcement into schemas and application validation, then expand the evaluation set as real failures appear. That process turns a prompt example into a maintainable component of an LLM application.

Related Topics

#prompt-engineering#prompt-library#json#developer-workflows
U

UCAFS Editorial Team

AI Development Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.