Inferensys

Prompt

Citation Numbering Sequence Repair Prompt Template

A practical prompt playbook for using Citation Numbering Sequence Repair Prompt Template in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for the Citation Numbering Sequence Repair prompt.

This prompt is for product teams and developers who operate RAG systems, documentation generators, or any AI feature that produces inline numeric citations (e.g., [1], [2], [3]) alongside a reference list. The core job-to-be-done is repairing a broken citation sequence after a model has inserted, deleted, or reordered claims, leaving the numbering non-sequential, duplicated, or mismatched between the body text and the reference list. The ideal user is an engineer integrating this repair step into a post-generation validation pipeline, where the output must be machine-readable and the citation integrity is a hard requirement for downstream consumers or compliance reviewers.

Use this prompt when you have a complete answer text and a complete reference list, but the numeric labels are out of sync. Typical failure signals include: a reference list with entries numbered 1 through 5 but inline citations that jump from [1] to [4]; duplicate citation numbers pointing to different sources; or a reference entry that is never cited in the body. This prompt is designed to be run as a deterministic repair step, not as a general-purpose answer generator. It assumes the underlying claims and source mappings are already correct and only the numbering sequence needs repair. Do not use this prompt when the citations themselves are hallucinated, when the reference list is incomplete, or when the mapping between claims and sources is broken—those failures require different repair playbooks such as Hallucinated Citation Removal or Citation-to-Evidence Alignment.

Before invoking this prompt, ensure you have a validated reference list where each entry is a distinct source and a body text where citation markers are the only thing that needs fixing. The prompt works best when the input is a single, complete artifact rather than a streaming fragment. If your system allows users to edit the generated text between generation and repair, you must re-run the repair step after any edit that adds or removes citations. For high-stakes domains such as legal, clinical, or financial documentation, always route the repaired output through a human review step and log the before/after citation map for auditability. The next section provides the copy-ready prompt template you can adapt into your repair harness.

PRACTICAL GUARDRAILS

Use Case Fit

Where this prompt works and where it does not. Understand the operational boundaries before embedding it in a production pipeline.

01

Good Fit: Post-Processing RAG Pipelines

Use when: A RAG system has already generated a response with numeric citations, but the numbering is non-sequential, has gaps, or contains duplicates. Guardrail: Run this prompt as a deterministic repair step after generation and before the response reaches the user. Validate the output with a script that checks for consecutive integers starting from 1.

02

Bad Fit: Real-Time Streaming Responses

Avoid when: Citations are being streamed token-by-token to a user interface. This prompt requires the full text and reference list to renumber correctly. Guardrail: Disable this repair step for streaming endpoints. Instead, buffer the complete response and apply the repair before final rendering.

03

Required Inputs: Complete Text and Reference List

What to watch: The prompt will hallucinate a new sequence if the original reference list is missing or incomplete. Guardrail: Always pass the full, unaltered reference list alongside the body text. Implement a pre-check that counts the number of references in the input and compares it to the output to ensure no references were dropped.

04

Operational Risk: Silent Citation Remapping

Risk: The model might renumber citations correctly but silently drop a reference that had no inline marker, altering the intended source list. Guardrail: Add a strict instruction in the prompt to preserve all original references, even if uncited. Implement a post-repair diff that flags any reference present in the input but missing from the output.

05

Operational Risk: Insertion and Deletion Drift

Risk: When the model inserts a new citation or deletes a broken one, it can shift the numbering of all subsequent citations, breaking the mapping to the original source chunks. Guardrail: The output must include a mapping table from old citation numbers to new citation numbers. Use this table to update any downstream metadata or source chunk pointers.

06

Variant: Multi-Turn Conversation Context

Use when: Citations span multiple conversation turns, and a new message introduces a reference that conflicts with a prior turn's numbering. Guardrail: Do not use this prompt on a single turn in isolation. Assemble the full conversation transcript and the cumulative reference list before running the repair to ensure global consistency across the session.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for repairing broken, skipped, or non-sequential citation numbering in model outputs.

This prompt template is designed to be dropped into a post-generation repair step. It takes a text body with inline citation markers and a reference list, then rewrites both so that numbering is consecutive, consistent, and free of gaps. The template uses square-bracket placeholders for all variable inputs, allowing you to parameterize it in your application code before sending it to the model.

text
You are a citation numbering repair system. Your job is to fix broken, skipped, or non-sequential numeric citation numbering in the provided text.

## INPUT
[BODY_WITH_CITATIONS]

[REFERENCE_LIST]

## CONSTRAINTS
[CONSTRAINTS]

## INSTRUCTIONS
1. Identify every inline citation marker in the body text. Markers may appear as [1], [2,3], [4-6], or similar numeric patterns.
2. Identify every reference entry in the reference list. Each entry should have a unique identifier (number, tag, or key).
3. Map each inline citation to its correct reference entry based on content matching, not current numbering.
4. Reassign consecutive numbers starting from 1 to all cited references in the order they first appear in the body text.
5. Rewrite the body text with corrected inline citation numbers.
6. Rewrite the reference list with corrected numbering, preserving all reference content and metadata.
7. If a reference is listed but never cited, append it to the end of the reference list with a note: [uncited].
8. If an inline citation points to a reference that does not exist in the list, flag it with [missing-reference] and do not assign it a number.
9. Do not alter any text except citation numbers and reference list ordering/numbering.
10. Preserve all formatting, whitespace, and non-citation content exactly.

## OUTPUT_SCHEMA
Return a JSON object with this exact structure:
{
  "repaired_body": "string (body text with corrected citation numbers)",
  "repaired_reference_list": "string (reference list with corrected numbering)",
  "citation_map": [
    {
      "original_number": "string or number",
      "new_number": "number",
      "reference_key": "string",
      "status": "repaired | uncited | missing-reference"
    }
  ],
  "warnings": ["string (any issues encountered)"]
}

## EXAMPLES
[EXAMPLES]

## RISK_LEVEL
[RISK_LEVEL]

To adapt this template, replace each placeholder with values from your application context. [BODY_WITH_CITATIONS] should contain the full text with inline citation markers. [REFERENCE_LIST] should contain the complete reference section. [CONSTRAINTS] can specify additional rules such as a maximum citation number, a required citation style, or domain-specific formatting requirements. [EXAMPLES] should include one or two worked examples showing the correct repair behavior for your citation format. [RISK_LEVEL] should be set to high if the output will be shown to users without human review, triggering additional validation and confidence checks before the repaired text is released.

After copying this template, wire it into a post-generation pipeline that runs after your primary model produces a response. Validate the output JSON against the schema before accepting it. If the warnings array contains entries or if any citation has a missing-reference status, route the output for human review or trigger a fallback repair strategy. For high-risk domains such as legal, medical, or financial content, always require human approval on repaired citations before publication.

IMPLEMENTATION TABLE

Prompt Variables

Required and optional inputs for the Citation Numbering Sequence Repair prompt. Each variable must be validated before the prompt is assembled to prevent downstream repair failures.

PlaceholderPurposeExampleValidation Notes

[DRAFT_TEXT]

The full text body containing broken inline citation markers that need repair

As noted in [3], the system requires recalibration [7]. Further tests [2] confirmed this.

Must be a non-empty string. Check for presence of numeric citation markers in brackets. If no markers found, skip repair and return input unchanged.

[REFERENCE_LIST]

The current reference list as it appears in the document, with original numbering

  1. Smith, J. (2023). System Design. 2. Chen, L. (2022). Calibration Methods. 3. Patel, R. (2024). Testing Frameworks.

Must be a non-empty string or structured list. Validate that each entry has a detectable reference number. If list is empty, set repair scope to inline-only.

[CITATION_STYLE]

The target citation format for the repaired output

numeric-bracket

Must be one of: numeric-bracket, numeric-superscript, numeric-parenthetical. Default to numeric-bracket if not specified. Reject unknown styles.

[REPAIR_SCOPE]

Defines whether to repair inline markers only, reference list only, or both

both

Must be one of: inline-only, reference-list-only, both. If reference-list-only is selected, [DRAFT_TEXT] may be null. If inline-only, [REFERENCE_LIST] may be null.

[INSERTION_HANDLING]

Strategy for handling citations that appear in the reference list but not in the body text

flag-as-orphan

Must be one of: flag-as-orphan, append-to-end, remove. Orphaned references are entries with no corresponding inline marker after renumbering.

[DELETION_HANDLING]

Strategy for handling inline markers that reference non-existent list entries

renumber-skip

Must be one of: renumber-skip, flag-as-broken, remove-marker. Broken markers are inline citations with no matching reference entry.

[OUTPUT_FORMAT]

The structure of the repaired output returned by the model

annotated-json

Must be one of: annotated-json, repaired-text-only, diff-format. annotated-json includes the repaired text plus a change log. repaired-text-only returns just the corrected document.

[CHANGE_LOG_LEVEL]

Granularity of the repair change log when OUTPUT_FORMAT is annotated-json

per-citation

Must be one of: per-citation, summary-only, none. per-citation logs each renumbering action. summary-only provides counts. none suppresses the log. Required only when OUTPUT_FORMAT is annotated-json.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Citation Numbering Sequence Repair prompt into a reliable application workflow with validation, retries, and quality gates.

The Citation Numbering Sequence Repair prompt is designed to be called as a post-generation repair step, not as the primary generation prompt. Wire it into your application after the initial model response is received and before the output is stored or displayed to the user. The typical integration point is inside a validation pipeline: your application receives a model-generated text with inline numeric citations and a reference list, runs a structural validator to detect numbering gaps, duplicates, or mismatches, and if validation fails, invokes this repair prompt with the original text and the validation error details. This keeps the repair prompt focused on a single task and avoids running it unnecessarily on outputs that are already correct.

For production implementation, wrap the prompt call in a retry loop with a maximum of 2-3 attempts. On each attempt, pass the previous repair output and any new validation errors back into the [PREVIOUS_ATTEMPT] and [VALIDATION_ERRORS] placeholders. If the output still fails validation after the retry budget is exhausted, escalate to a human review queue rather than silently accepting broken citations. Log every repair attempt with the input text hash, validation error counts, repair duration, and final pass/fail status. This audit trail is essential for debugging model drift and for compliance workflows where citation integrity is a hard requirement. Use structured logging fields: citation_repair_attempt, input_citation_count, output_citation_count, gaps_found, gaps_resolved, validation_passed.

Model choice matters here. This task requires precise instruction following and structured output adherence, not creative generation. Use a model with strong JSON mode or structured output support, such as GPT-4o, Claude 3.5 Sonnet, or Gemini 1.5 Pro, configured with a strict output schema that enforces the repaired text and the repair audit log as separate fields. Avoid models that tend to paraphrase or rewrite surrounding content—the repair must preserve all non-citation text exactly. Set temperature to 0 or near-zero to minimize variability. If your application uses streaming, buffer the complete output before running repair; partial streams will produce false-positive validation failures and waste repair attempts.

The repair prompt's output should be validated programmatically before acceptance. Implement a post-repair validator that checks: (1) every inline citation number has a corresponding entry in the reference list, (2) reference list numbering is consecutive starting from 1 with no gaps, (3) no citation numbers appear in the reference list that aren't used inline, and (4) the non-citation text content is byte-identical to the original input except for the repaired citation numbers. This last check prevents the model from silently rewriting content during repair. If any check fails, feed the specific failure details into the next retry attempt's [VALIDATION_ERRORS] placeholder. For high-stakes domains like legal or medical documentation, always require human review of the repair audit log before the output is published, even if all automated validations pass.

IMPLEMENTATION TABLE

Expected Output Contract

Defines the exact structure, types, and validation rules for the repaired citation output. Use this contract to build a parser that can automatically verify the model's response before accepting it into downstream systems.

Field or ElementType or FormatRequiredValidation Rule

repaired_text

string

Must contain all original body text with repaired inline citation markers. Inline markers must be strictly sequential integers starting from 1, enclosed in square brackets (e.g., [1], [2]). No gaps, duplicates, or out-of-order markers allowed.

reference_list

array of objects

Array length must equal the maximum inline citation number found in repaired_text. Each entry must have a matching index (1-based). No orphaned references without a corresponding inline marker.

reference_list[].id

integer

Must be a positive integer matching the citation number used in repaired_text. Must be unique within the array and strictly sequential starting from 1.

reference_list[].content

string

Must contain the full reference text as a non-empty string. Content must match a reference from the original [INPUT_TEXT] or be a deduplicated/merged version of an original reference. No hallucinated references allowed.

repair_log

array of objects

Must contain one entry for every repair action taken. If no repairs were needed, array must be empty. Each entry must describe the original state, the action taken, and the affected citation numbers.

repair_log[].original_issue

string

Must describe the specific problem found using one of these categories: 'gap_in_sequence', 'duplicate_number', 'non_sequential_start', 'orphaned_reference', 'missing_inline_citation', or 'mismatched_reference_count'.

repair_log[].action_taken

string

Must describe the concrete repair performed, referencing specific citation numbers before and after the change. Example: 'Renumbered citations [3,5,7] to [3,4,5] to close gaps from missing citations 4 and 6.'

confidence_score

number

If present, must be a float between 0.0 and 1.0 indicating overall confidence in the repair. Score below 0.7 should trigger a human review flag in the calling application. Null allowed if confidence estimation is not implemented.

PRACTICAL GUARDRAILS

Common Failure Modes

Citation numbering repair fails in predictable ways. These are the most common production failure modes and the guardrails that catch them before they reach users.

01

Orphaned Inline Markers

What to watch: Inline citation markers like [3] or [7] remain in the text after the model removes or renumbers the corresponding reference entry. The marker points to nothing, breaking traceability. Guardrail: Post-repair validation that extracts all inline markers and confirms each has a matching entry in the reference list. Flag any orphan for manual correction or re-insertion.

02

Reference List Drift

What to watch: The model renumbers inline citations but forgets to renumber the reference list, or vice versa. The two sequences diverge, making every citation untrustworthy. Guardrail: Run a cross-reference check that pairs each inline marker with its reference list entry by position and content. Reject outputs where the counts or pairings don't match exactly.

03

Silent Content Swaps

What to watch: During renumbering, the model accidentally swaps the content of two references—reference [2] now contains the text that belonged to reference [5]. The numbering looks correct but the attribution is wrong. Guardrail: Before-and-after content hashing per reference entry. Compare the text of each reference before and after repair. Flag any entry where the content changed beyond whitespace normalization.

04

Gap Introduction

What to watch: The model skips a number in the sequence—inline markers go [1], [2], [4], [5]—leaving a gap that downstream parsers reject. This often happens when the model removes a duplicate citation but forgets to close the gap. Guardrail: Sequence continuity check that verifies inline markers form a consecutive integer sequence starting from 1. Reject any output with gaps or non-sequential numbering.

05

Insertion Collision

What to watch: When new citations are inserted mid-document, the model reuses existing numbers instead of shifting the sequence, creating duplicate markers like two different [3] citations. Guardrail: Uniqueness validation on all inline markers. If any number appears more than once, flag the collision and require a full resequencing pass with explicit insertion-point instructions.

06

Truncation at Token Boundary

What to watch: The repair prompt runs near the model's output token limit. The reference list gets cut off mid-entry, leaving the last few citations dangling with no corresponding reference text. Guardrail: End-of-output completeness check that verifies the final reference entry is syntactically complete and the reference count matches the highest inline marker. If truncated, request continuation with the truncated entry as context.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for testing the Citation Numbering Sequence Repair prompt before deployment. Run these checks on a golden dataset of 20-30 broken citation examples to establish a pass/fail baseline.

CriterionPass StandardFailure SignalTest Method

Inline-to-Reference Sequence Match

Every inline citation number [n] maps to a reference list entry numbered n, and vice versa

Mismatched count between inline markers and reference entries; orphaned inline numbers with no reference target

Parse all inline markers and reference list numbers; assert set equality and 1:1 mapping

Consecutive Numbering

Inline citation numbers form a strictly increasing sequence starting at 1 with no gaps (1,2,3...N)

Skipped numbers (1,3,5) or non-sequential ordering (1,3,2) in the repaired output

Extract ordered inline citation numbers; assert sequence equals range(1, len(sequence)+1)

Reference List Ordering

Reference list entries are ordered by their assigned number, matching the first appearance order in the text

Reference list order does not match first-appearance order; entry numbered 3 appears before entry numbered 2

Compare reference list order against first-appearance index of each citation in the body text

No Citation Content Loss

All unique cited sources from the original broken output appear in the repaired reference list

A source cited in the original text is missing from the repaired reference list

Extract unique source identifiers from original inline citations; assert all are present in repaired reference list

No Hallucinated Citations

No new citations or reference entries are invented that were not present in the original broken input

Repaired output contains a citation number or reference entry with no corresponding source in the original

Diff original and repaired citation sets; flag any additions not attributable to renumbering

Insertion Handling

When a new citation is inserted mid-text, all subsequent numbers shift correctly and reference list updates accordingly

Inserted citation breaks the sequence; subsequent numbers fail to increment; reference list entry appears at wrong position

Provide test case with explicit insertion; verify numbering shift and reference list reorder

Deletion Handling

When a citation is removed, numbering collapses the gap and the corresponding reference entry is removed

Gap remains in numbering sequence; deleted citation's reference entry still appears in the list

Provide test case with explicit deletion; verify gap closure and reference list cleanup

Multi-Citation Cluster Integrity

Clusters like [1,2,4] are renumbered to consecutive values while preserving distinct source references

Cluster members are merged into a single number or lose their distinct reference mappings

Test with multi-citation clusters; verify each cluster member maps to correct renumbered reference

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a small, hand-verified test set. Focus on getting the numbering logic right before adding production constraints. Strip optional fields like [OUTPUT_SCHEMA] and [CONFIDENCE_THRESHOLD] to keep the prompt lean.

code
You are a citation numbering repair assistant. Given a text with inline citation markers and a reference list, repair the numbering so that citations are sequential starting from 1, and every inline marker matches a reference list entry.

### Input
[TEXT_WITH_CITATIONS]

### Reference List
[REFERENCE_LIST]

### Instructions
1. Map every inline citation marker to its corresponding reference.
2. Renumber citations consecutively in order of first appearance.
3. Update the reference list to match the new numbering.
4. Flag any inline citation that has no matching reference.
5. Flag any reference that is never cited.

### Output
Return the repaired text and reference list.

Watch for

  • Off-by-one errors when the original numbering starts at 0 or skips numbers
  • Citations that appear only in the reference list but not in the text
  • Model reordering references instead of just renumbering them
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.