Inferensys

Prompt

Record Update Field Comparison Prompt

A practical prompt playbook for agents that modify existing records and must confirm only intended fields changed, producing a structured before/after diff with unintended change flags and rollback suggestions.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Use this prompt to verify that a database record, API resource, or configuration object was mutated correctly by comparing pre- and post-update snapshots and flagging unintended field changes.

This prompt is designed for the postcondition verification stage of an agent pipeline, after a mutation step claims success but before the next step consumes the updated record. It solves a specific operational problem: agents that modify existing records can silently corrupt data by altering fields they were not supposed to touch, dropping fields entirely, or letting system-managed columns like updated_at mask real data loss. The prompt takes two snapshots—a pre-update state and a post-update state—and produces a field-level diff that separates intended changes from unintended ones, with explicit rollback suggestions when corruption is detected.

The ideal user is an agent runtime developer or platform engineer building validation layers into autonomous workflows. You should wire this prompt into a harness that captures the record state before the mutation step executes, then feeds both snapshots into the prompt after the mutation step returns. The prompt expects a declared list of intended changes as part of its input, which typically comes from the agent's own plan or tool call arguments. Without that declared-intent list, the prompt can still produce a raw diff, but it cannot distinguish between legitimate updates and silent corruption. Use this prompt when the cost of undetected field corruption is high—financial records, compliance data, user profile mutations, or configuration changes that affect downstream system behavior.

Do not use this prompt for schema validation, type checking, or output contract enforcement. Those concerns belong to separate validation prompts that check structure rather than semantic correctness. Do not use it when the record has hundreds of fields and the intended change list is unknown; the prompt will produce noisy diffs that are expensive to review and easy to ignore. In high-throughput pipelines where latency budgets are tight, consider sampling-based verification or deferring full field comparison to an asynchronous audit path. For regulated domains, always log the diff output alongside the agent's action trail and require human review when unintended changes are flagged with severity above a defined threshold.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Record Update Field Comparison Prompt works, where it fails, and what you must provide before trusting the output.

01

Good Fit: Structured Record Updates

Use when: an agent modifies a known record in a database, CRM, or configuration store and you need to confirm only the intended fields changed. Guardrail: Provide the full before and after record payloads plus the declared intent of the update. The prompt compares field-level diffs against that intent.

02

Bad Fit: Unstructured or Free-Text Diffs

Avoid when: the before and after states are free-text documents, chat transcripts, or narrative summaries without a stable field schema. Guardrail: Use a document-level change summary prompt instead. This prompt requires named fields with discrete values to produce reliable diffs.

03

Required Input: Intent Declaration

Risk: Without an explicit statement of which fields the agent intended to change, the prompt cannot distinguish authorized from unauthorized modifications. Guardrail: Always pass a structured intent block listing target fields and expected new values alongside the before/after records.

04

Operational Risk: Timestamp and Audit-Field Noise

Risk: System-generated fields like updated_at, last_modified_by, or version change on every write and can mask real unintended changes in the diff output. Guardrail: Pre-filter known system fields from the comparison or include an ignore-list parameter in the prompt template so the model focuses on business fields only.

05

Operational Risk: Partial or Nested Object Updates

Risk: When records contain nested JSON or arrays, a shallow field comparison may miss changes deep inside objects or misreport entire nested blocks as changed. Guardrail: Specify the comparison depth in the prompt and require the model to flag nested diffs with path notation so no subfield change goes unreported.

06

Bad Fit: High-Volume Streaming Updates

Avoid when: you need to validate thousands of record updates per second in a streaming pipeline. Guardrail: This prompt is designed for step-level agent verification, not bulk validation. For high-throughput use cases, implement a deterministic field-comparison function in application code and reserve the prompt for sampled audits or anomaly review.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt that compares a record's state before and after an agent's update step, flags unintended changes, and recommends rollback actions.

The following prompt is designed to be pasted directly into your agent's postcondition validation step. It instructs the model to perform a strict field-level comparison between a pre-update and post-update record snapshot. The goal is to confirm that only the fields the agent intended to modify were actually changed, and that no unintended side effects—such as overwritten audit fields, timestamp noise, or cascading defaults—corrupted the record. Replace every square-bracket placeholder with the actual values from your application context before sending this prompt to the model.

text
You are a record integrity validator for an autonomous agent system. Your job is to compare a record's state before and after an agent-performed update and determine whether only the intended fields were modified.

# INPUT
- Pre-Update Record: [PRE_UPDATE_RECORD_JSON]
- Post-Update Record: [POST_UPDATE_RECORD_JSON]
- Intended Modifications: [INTENDED_MODIFICATIONS_LIST]
- Ignored Fields (e.g., timestamps, audit fields): [IGNORED_FIELDS_LIST]

# TASK
1. Compute the field-level diff between the pre-update and post-update records.
2. Classify each changed field into one of three categories:
   - **INTENDED**: The field is in the Intended Modifications list and its new value matches the intended change.
   - **UNINTENDED**: The field changed but is NOT in the Intended Modifications list and is NOT in the Ignored Fields list.
   - **NOISE**: The field changed but is in the Ignored Fields list (e.g., `updated_at`, `last_modified_by`).
3. For each UNINTENDED change, assess the severity: LOW (cosmetic), MEDIUM (data integrity risk), HIGH (security, compliance, or business logic violation).
4. If any UNINTENDED changes are found, generate a rollback suggestion that restores the original values for those fields.

# OUTPUT_SCHEMA
Return a single JSON object with this exact structure:
{
  "overall_verdict": "PASS" | "FAIL" | "WARNING",
  "intended_changes": [
    {
      "field": "string",
      "old_value": "any",
      "new_value": "any",
      "matches_intent": true | false
    }
  ],
  "unintended_changes": [
    {
      "field": "string",
      "old_value": "any",
      "new_value": "any",
      "severity": "LOW" | "MEDIUM" | "HIGH",
      "description": "string explaining the risk"
    }
  ],
  "noise_changes": [
    {
      "field": "string",
      "old_value": "any",
      "new_value": "any"
    }
  ],
  "rollback_actions": [
    {
      "field": "string",
      "restore_value": "any",
      "command": "string describing the rollback operation"
    }
  ]
}

# CONSTRAINTS
- Do not flag fields in the Ignored Fields list as UNINTENDED; classify them as NOISE.
- If an intended field's new value does not match the expected value, classify it as UNINTENDED with a description of the mismatch.
- If no unintended changes are found, set overall_verdict to "PASS" and return empty arrays for unintended_changes and rollback_actions.
- If only NOISE changes are found alongside intended changes, set overall_verdict to "PASS".
- If unintended changes are LOW severity only, set overall_verdict to "WARNING".
- If any MEDIUM or HIGH severity unintended changes exist, set overall_verdict to "FAIL".
- Do not invent fields or values not present in the input records.

# RISK_LEVEL
[HIGH] This validation gates downstream agent steps that may depend on record integrity. A false PASS can corrupt multi-step workflows. A false FAIL can stall legitimate operations. Human review is required for FAIL verdicts before rollback execution.

To adapt this prompt for your own agent pipeline, start by defining your [IGNORED_FIELDS_LIST] carefully. Every system has fields that change on every write—updated_at timestamps, version counters, or last_modified_by user IDs. If you omit these from the ignored list, the prompt will flag them as unintended changes on every run, producing noisy FAIL verdicts. Conversely, if you add business-logic fields to the ignored list to suppress warnings, you risk masking real data corruption. Maintain this list as a configuration parameter that evolves with your schema, not a one-time hardcode. For the [INTENDED_MODIFICATIONS_LIST], pass the exact field-value pairs your agent's update step was instructed to apply. If your agent uses a dynamic update payload, extract the intended changes from the tool call arguments or the step's declared postconditions. After pasting this prompt into your validation harness, always run it against a set of known test cases—including records with only noise changes, records with a single unintended change, and records where an intended field was set to the wrong value—to confirm the verdict logic behaves as expected before deploying to production.

IMPLEMENTATION TABLE

Prompt Variables

Every placeholder the Record Update Field Comparison Prompt expects, why it matters, and how to validate it before sending to the model.

PlaceholderPurposeExampleValidation Notes

[RECORD_TYPE]

Declares the entity type being updated so the model applies domain-specific field knowledge and audit expectations.

customer_account

Must match a known entity in your schema registry. Reject if not in allowed list or null.

[BEFORE_STATE]

The full record snapshot before the update operation. Used as the baseline for field-level comparison.

{"id": 482, "status": "active", "tier": "pro", "updated_at": "2025-01-15T10:00:00Z"}

Must be valid JSON. Schema must match [RECORD_TYPE] definition. Timestamp fields must parse as ISO 8601. Reject if empty object or null.

[AFTER_STATE]

The full record snapshot after the update operation. Compared field-by-field against [BEFORE_STATE] to detect changes.

{"id": 482, "status": "suspended", "tier": "pro", "updated_at": "2025-01-15T10:05:00Z"}

Must be valid JSON. Schema must match [RECORD_TYPE] definition and be structurally compatible with [BEFORE_STATE]. Reject if identical to [BEFORE_STATE] with no changes or null.

[INTENDED_CHANGES]

A list of fields the agent explicitly intended to modify, used to separate expected changes from unexpected side effects.

["status"]

Must be a non-empty array of strings. Each string must match a top-level key present in both [BEFORE_STATE] and [AFTER_STATE]. Reject if empty or contains unknown field names.

[AUDIT_FIELD_PATTERNS]

Regex or glob patterns identifying metadata fields that should be excluded from unexpected-change flagging.

["updated_at", "modified_by", "_version"]

Must be an array of strings. Each pattern must be a valid regex or exact field name. Reject if empty or contains patterns that match all fields.

[OUTPUT_SCHEMA]

The expected JSON schema for the comparison output, defining the structure of the diff, flags, and rollback suggestions.

{"type": "object", "properties": {"changed_fields": {"type": "array"}, "unexpected_changes": {"type": "array"}, "rollback_suggestions": {"type": "array"}}}

Must be a valid JSON Schema draft-07 or later. Must include required fields: changed_fields, unexpected_changes, rollback_suggestions. Reject if schema allows arbitrary additional properties without constraint.

[CONSTRAINTS]

Operational rules the model must follow, such as sensitivity thresholds, field-level ignore lists, or rollback scope limits.

"Flag only value changes, not key reordering. Treat null-to-empty-string as a change. Never suggest rollback for audit fields."

Must be a non-empty string. Should not contradict [AUDIT_FIELD_PATTERNS]. Reject if contains instructions to ignore all changes or skip validation entirely.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Record Update Field Comparison Prompt into an agent pipeline with pre-processing, post-processing, retry logic, and human review gates.

The Record Update Field Comparison Prompt is designed to sit at a critical gating point in an agent pipeline: immediately after a tool call that mutates an existing database record. Its job is to compare the pre-mutation and post-mutation state of the record and confirm that only the intended fields changed. This is not a general-purpose diff tool; it is a targeted safety check for agents operating on mutable resources where an undetected field corruption can silently poison downstream reasoning. The harness must therefore treat this prompt as a mandatory validation step, not an optional diagnostic. If the prompt flags an unintended change, the pipeline should halt, roll back, or escalate—never proceed blindly.

To wire this prompt into an application, start by capturing a snapshot of the target record before the mutation tool executes. Store this as a structured JSON object in the agent's short-term memory or a dedicated pre_state variable. After the mutation tool returns a success response, retrieve the same record again to capture the post_state. Both states must be normalized to the same schema before they are passed to the prompt. Common normalization steps include stripping internal metadata fields (e.g., _id, _rev, _etag), converting timestamps to a consistent format, and removing computed or auto-generated fields that are expected to change on every write. If you skip normalization, the prompt will drown in noise from audit timestamps and revision tokens, producing false-positive unintended-change flags that erode trust in the validation layer.

The prompt's input variables are [PRE_STATE], [POST_STATE], and [INTENDED_CHANGES]. [INTENDED_CHANGES] should be a structured description of which fields the agent intended to modify and their expected new values. This is not the same as the raw tool arguments; it is a declarative statement of intent that the agent should produce before calling the mutation tool. For example: 'Update status to "active" and set last_contacted to 2025-03-15T10:00:00Z. No other fields should change.' The harness should validate that [INTENDED_CHANGES] is present and well-formed before invoking the prompt. If the agent cannot articulate its intent, the pipeline should refuse to execute the mutation.

Post-processing the prompt's output requires a structured parser that expects a JSON object with at minimum three keys: unintended_changes (an array of field-level diffs), rollback_recommended (a boolean), and rollback_actions (a list of suggested corrective steps). The harness should validate this schema strictly. If the model returns malformed JSON, retry once with a repair prompt that includes the raw output and the expected schema. If the second attempt also fails, escalate to a human operator with the raw output and both state snapshots. Do not silently proceed past a schema validation failure—this is the exact scenario where the safety check is most needed.

Retry logic for this prompt should be conservative. A single retry on schema validation failure is acceptable. Do not retry on semantic findings—if the prompt reports unintended changes, the harness must treat that as a definitive signal, not a probabilistic one to be re-rolled. The model may occasionally flag a benign field update (e.g., a last_modified timestamp that normalization missed) as unintended. To handle this, implement a post-processing allowlist of fields that are known to be safe to ignore. If all flagged unintended changes match the allowlist, the harness can suppress the alert and proceed. If any flagged field is outside the allowlist, halt execution and route to a human review queue with the full diff, the agent's intended changes, and the prompt's raw output.

Human review gates are essential when this prompt fires in production. The review interface should display a side-by-side diff of the pre-state and post-state records, highlight the fields the agent intended to change, and visually flag any unintended changes detected by the prompt. The human reviewer should have one-click actions to approve the change (overriding the prompt's warning), roll back the record to its pre-state, or manually correct the corrupted fields. Every review decision must be logged with the reviewer's identity, timestamp, and action taken. This audit trail is critical for debugging agent behavior and for compliance in regulated environments where automated data mutations require traceable oversight.

Model choice matters for this prompt. The task requires precise field-by-field comparison with low tolerance for hallucinated diffs. Use a model with strong structured output capabilities and low error rates on detail-oriented comparison tasks. Avoid models known to summarize or elide differences. Set the temperature to 0 or near-zero to minimize variance. If your pipeline uses a smaller, faster model for cost reasons, consider routing this specific validation step to a more capable model—the incremental cost is trivial compared to the cost of undetected data corruption propagating through downstream agent steps.

IMPLEMENTATION TABLE

Expected Output Contract

The JSON schema, field descriptions, and validation rules your harness should enforce on the model's response for a Record Update Field Comparison.

Field or ElementType or FormatRequiredValidation Rule

[BEFORE_RECORD]

object

Schema check: must match the structure of the input record exactly, including all nested fields and data types.

[AFTER_RECORD]

object

Schema check: must match the structure of the input record exactly. Parse check: confirm it is not a byte-for-byte copy of [BEFORE_RECORD].

changed_fields

array of objects

Schema check: each object must contain 'field_path' (string), 'before_value' (any), 'after_value' (any). Parse check: array must not be empty if [BEFORE_RECORD] and [AFTER_RECORD] differ.

unintended_changes

array of objects

Schema check: each object must contain 'field_path' (string), 'before_value' (any), 'after_value' (any), 'reason' (string). Parse check: must include any changes to fields like 'updated_at', 'version', 'last_modified_by' if present.

rollback_suggestions

array of strings

Null check: must be null or an empty array if 'unintended_changes' is empty. Parse check: each string must describe a specific, reversible action for an unintended change.

audit_noise_detected

boolean

Type check: must be a strict boolean. Logic check: must be 'true' if any change is solely to a timestamp or audit field.

comparison_summary

string

Parse check: must be a single sentence confirming the number of intended and unintended changes detected. Approval required if 'unintended_changes' is not empty.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when comparing record fields before and after an agent update, and how to prevent silent data corruption.

01

Timestamp Noise Masks Real Changes

What to watch: The model reports a clean diff because it treats updated_at or last_modified timestamp changes as expected metadata rather than noise. Real field mutations hide behind routine timestamp updates. Guardrail: Explicitly exclude timestamp, audit, and auto-generated fields from the comparison scope in the prompt. Require the model to list every field it considers before declaring no changes.

02

Nested Object Partial Comparison

What to watch: The model compares nested JSON or dictionary fields at the top-level reference rather than performing deep field-by-field comparison. A changed sub-field inside a metadata or config object goes undetected. Guardrail: Instruct the model to recursively expand nested objects and arrays, producing a flattened field-path diff. Validate output contains leaf-level paths, not just parent keys.

03

Type Coercion Hides Value Drift

What to watch: The model treats "5" and 5 as equivalent, or null and `

04

Unintended Cascade Changes Missed

What to watch: An agent updates one field but a trigger, default, or ORM lifecycle hook modifies additional fields. The model reports only the intended change and misses the cascade. Guardrail: Ask the model to enumerate all changed fields first, then separately classify each as intended or unintended. Require explicit justification for any field marked intended.

05

Large Payload Truncation

What to watch: The before/after payloads exceed the model's effective attention or context window, causing the model to compare only the first portion of the record. Fields in the tail are silently skipped. Guardrail: Chunk large records by field group and run comparison per chunk. Add a completeness check that counts fields in the input versus fields mentioned in the diff output.

06

Rollback Suggestion Scope Creep

What to watch: The model suggests rolling back more fields than necessary, including unrelated changes from prior legitimate updates, because it cannot distinguish the current agent's changes from earlier ones. Guardrail: Provide the specific agent action intent alongside the before/after snapshots. Constrain rollback suggestions to only fields the agent was authorized to modify.

IMPLEMENTATION TABLE

Evaluation Rubric

Run these checks against a golden dataset of known record update scenarios to test output quality before shipping this prompt into production.

CriterionPass StandardFailure SignalTest Method

Field Change Accuracy

All intended changes are correctly identified with exact before/after values; no false positives on unchanged fields

Missing a changed field or flagging a field that was not actually modified

Compare prompt output against a golden dataset with known field mutations; require 100% recall and precision on change detection

Unintended Change Flagging

Any field modified outside the [INTENDED_CHANGES] list is flagged with severity HIGH and a rollback suggestion

An unintended mutation appears in the output without a HIGH severity flag or rollback recommendation

Inject a side-effect mutation into a test record; verify the prompt output includes the field, severity=HIGH, and a non-empty rollback suggestion

Timestamp and Audit Field Noise Filtering

System-managed fields like updated_at, last_modified_by, or revision_id are correctly classified as NOISE and excluded from unintended change reports

A timestamp or audit field appears in the unintended changes list with a severity other than NOISE

Use records where only system fields changed; confirm the prompt classifies all such fields as NOISE and does not recommend rollback

Before/After Value Fidelity

Every reported field change includes the exact pre-update and post-update values as they appear in the input snapshots

A before or after value is truncated, hallucinated, or does not match the provided [BEFORE_RECORD] or [AFTER_RECORD]

Spot-check 20 field diffs across 5 test scenarios; require exact string match between prompt output values and input snapshot values

Rollback Suggestion Completeness

For each unintended change flagged as HIGH or MEDIUM severity, the rollback suggestion includes the field name, target value, and a reversible action statement

A HIGH severity unintended change has a missing, empty, or non-actionable rollback suggestion

Parse the output for each HIGH/MEDIUM unintended change; assert rollback_suggestion.field is non-null, rollback_suggestion.target_value matches the before-record value, and rollback_suggestion.action is a non-empty string

Output Schema Conformance

The output is valid JSON matching the declared [OUTPUT_SCHEMA] with all required fields present and correct types

JSON parse failure, missing required field, or type mismatch on any field

Validate output against the schema using a JSON schema validator; reject any output that fails structural validation before running semantic checks

Empty Diff Handling

When [BEFORE_RECORD] and [AFTER_RECORD] are identical, the output reports zero intended changes, zero unintended changes, and a summary stating no modifications detected

Identical records produce a non-empty change list or a summary that claims modifications occurred

Supply two identical record snapshots; assert intended_changes.length === 0, unintended_changes.length === 0, and summary contains a no-change indicator

Partial Update Boundary

When [INTENDED_CHANGES] specifies a subset of fields, only those fields are expected in the intended changes list; all other modifications are treated as unintended

An intended change is misclassified as unintended, or an unintended change is misclassified as intended

Use a scenario where 3 of 5 changed fields are declared as intended; verify the prompt correctly separates the 3 intended from the 2 unintended with no crossover

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a single before/after record pair. Use a frontier model with a simple system message: "You are a data auditor. Compare the two records and report only the fields that changed." Skip strict JSON schema enforcement initially—accept markdown tables or bullet lists while you iterate on field coverage.

Add a lightweight instruction: "If you are unsure whether a field changed, flag it as [NEEDS REVIEW] rather than guessing."

Watch for

  • Timestamp and audit fields (updated_at, last_modified_by) appearing in every diff and masking real changes
  • The model summarizing changes instead of producing a field-by-field diff
  • Null-to-empty-string and empty-string-to-null being reported as meaningful changes
  • Large text fields triggering verbose explanations instead of concise change flags
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.