Inferensys

Prompt

Null Handling Demonstration Prompt for Missing Data

A practical prompt playbook for using Null Handling Demonstration Prompt for Missing Data 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

Defines the precise job-to-be-done for the null handling prompt, identifying the target user, required context, and clear boundaries where the prompt should not be applied.

This prompt is for integration engineers building extraction pipelines that must survive incomplete, messy, or partially redacted source text. Its primary job is to teach the model a deterministic contract for representing missing data, distinguishing between an empty string, a genuinely missing field, and a field that should be explicitly null. Use this when downstream consumers—such as strict-schema databases, typed APIs, or analytics systems—break on empty string substitution or silent field omission. The target reader is an engineer who needs predictable null behavior in a production data pipeline, not a content author or someone doing creative text generation.

The prompt works by providing carefully constructed few-shot examples that demonstrate the correct output for three distinct cases: a field with an empty value (""), a field that is entirely absent from the source (null), and a field that is present but contains no meaningful data (also null, depending on the contract). Counterexamples are included to show incorrect behaviors like substituting an empty string for a missing field or silently dropping a field that should be present. This is critical when the output feeds directly into systems that validate JSON Schema with "type": ["string", "null"] or database columns with NOT NULL constraints. The prompt is designed to be prepended to your existing extraction instructions, adding a null-handling layer without rewriting your core schema.

Do not use this prompt for summarization, creative text generation, or workflows where null semantics are not contract-critical. If your downstream consumer treats a missing key and a null value identically, the added token cost and complexity are unnecessary. Similarly, avoid this prompt when the model's base behavior already aligns with your null contract—over-specifying can sometimes degrade output quality. Before deploying, run the prompt against a golden test set that includes empty strings, missing fields, and explicit null values, and validate the output with a schema validator that enforces your exact nullability rules. If the extraction involves regulated data, add a human review step for any record where the model's null decision conflicts with a confidence threshold.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Null Handling Demonstration Prompt delivers value and where it introduces risk.

01

Good Fit: Downstream Schema Enforcement

Use when: Your extraction pipeline feeds a strict database, API, or analytics schema that rejects missing fields or empty strings. Guardrail: Use few-shot examples to teach explicit null vs "" representation so the model output passes schema validation without post-processing hacks.

02

Good Fit: Audit-Ready Extraction Logs

Use when: You need to prove that a field was absent from the source rather than merely empty. Guardrail: Include counterexamples showing incorrect empty-string substitution to train the model to preserve the distinction between missing data and intentionally blank values.

03

Bad Fit: Free-Text Summarization

Avoid when: The task is prose generation or narrative summarization without a fixed output schema. Guardrail: Null-handling demonstrations add token overhead and confuse models when no structured contract exists. Use schema-first prompts only when a machine-readable output is required downstream.

04

Required Input: Diverse Null-Pattern Examples

Risk: A prompt with only one null example teaches brittle behavior that fails on unseen missing-data patterns. Guardrail: Curate at least 3–5 examples covering missing fields, empty strings, partial objects, and fields present-but-null to ensure the model generalizes across null representations.

05

Operational Risk: Silent Field Omission

Risk: The model omits a field entirely instead of marking it null, causing downstream schema violations that are hard to detect. Guardrail: Add a post-extraction validator that checks for required-field presence and triggers a repair prompt or human review when fields are missing from the output object.

06

Operational Risk: Null vs. Empty String Collapse

Risk: The model treats null and "" as interchangeable, corrupting analytics that depend on the distinction. Guardrail: Include explicit counterexamples in the prompt showing both cases side by side, and add an eval check that verifies the output preserves the correct null/empty distinction for known test inputs.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt template that uses few-shot examples to teach explicit null handling, empty string vs. null distinction, and missing field annotation for robust extraction pipelines.

This template is designed to be pasted directly into your system prompt or as a user message in your extraction pipeline. Its core teaching mechanism is the set of few-shot examples, which demonstrate the exact behavior you expect for null, empty, and missing fields. The examples are not optional; they are the primary instruction set. Do not remove them without replacing them with equivalent demonstrations that cover the same edge cases. The placeholders in square brackets, such as [TARGET_SCHEMA] and [INPUT_TEXT], must be replaced with your specific schema and data before use.

text
You are a precise data extraction engine. Your only job is to extract information from the provided text and populate a JSON object that strictly conforms to the provided schema.

# Output Schema
You must output a single JSON object with the following fields. Do not add any fields that are not listed here.
[TARGET_SCHEMA]

# Critical Rules for Missing Data
1.  **Explicit Null:** If a field is mentioned in the text but its value is explicitly stated as unknown, not applicable, or null, you must output the JSON value `null`.
2.  **Empty String:** If a field is mentioned but its value is an empty string (e.g., "the comment field was left blank"), you must output the JSON value `""`.
3.  **Missing Field:** If a field in the schema is not mentioned at all in the input text, you must omit the key entirely from the output JSON object. Do not output the key with a null value.

# Examples
Follow the pattern demonstrated in these examples exactly.

## Example 1: Standard Extraction
Input:
"Customer: Acme Corp, Contact: John Doe, Phone: 555-0100, Email: [email protected]"
Output:
{
  "customer_name": "Acme Corp",
  "contact_name": "John Doe",
  "phone_number": "555-0100",
  "email_address": "[email protected]",
  "secondary_phone": null,
  "notes": ""
}

## Example 2: Explicit Null and Empty String
Input:
"Customer: Globex, Contact: Jane Smith. The secondary phone is not available. Notes field was left blank."
Output:
{
  "customer_name": "Globex",
  "contact_name": "Jane Smith",
  "phone_number": null,
  "email_address": null,
  "secondary_phone": null,
  "notes": ""
}

## Example 3: Missing Field (Key Omission)
Input:
"Customer: Initech, Contact: Bill Lumbergh"
Output:
{
  "customer_name": "Initech",
  "contact_name": "Bill Lumbergh"
}

## Example 4: Counterexample - Incorrect Null Substitution
Input:
"Customer: Initech, Contact: Bill Lumbergh"
Incorrect Output (Do not do this):
{
  "customer_name": "Initech",
  "contact_name": "Bill Lumbergh",
  "phone_number": "",
  "email_address": "",
  "secondary_phone": "",
  "notes": ""
}
This is incorrect because missing fields were filled with empty strings instead of being omitted.

# Input Text to Process
[INPUT_TEXT]

# Your JSON Output:

To adapt this template, start by replacing [TARGET_SCHEMA] with your own JSON schema. Ensure your schema includes fields that can test all three null-handling states. Next, replace the examples with your own domain-specific examples that mirror the exact patterns shown: one for standard extraction, one demonstrating explicit null and empty strings, one demonstrating key omission for missing data, and one counterexample showing an incorrect pattern. Finally, replace [INPUT_TEXT] with the actual text you want to process. For high-risk domains like healthcare or finance, add a [RISK_LEVEL] placeholder and a final instruction like: "If the input is ambiguous or could lead to an incorrect medical/financial assertion, output a JSON object with a single key "error" and a descriptive message, and halt further processing."

IMPLEMENTATION TABLE

Prompt Variables

Inputs the prompt needs to work reliably. Validate each before sending. This table defines the placeholders, their purpose, concrete examples, and actionable validation checks for the Null Handling Demonstration Prompt.

PlaceholderPurposeExampleValidation Notes

[RAW_INPUT_TEXT]

The unstructured text from which data must be extracted. May contain missing or ambiguous fields.

The patient's name is John Doe. Lab results are pending.

Check: non-empty string. If null or empty, the prompt should be aborted before sending.

[TARGET_SCHEMA]

A JSON schema definition specifying the exact fields, types, and nullability rules for the output.

{"type": "object", "properties": {"name": {"type": ["string", "null"]}, "age": {"type": ["integer", "null"]}}, "required": ["name", "age"]}

Check: must parse as valid JSON Schema. Validate that all fields have explicit null type union if missing data is expected.

[POSITIVE_EXAMPLES]

A set of few-shot examples demonstrating correct extraction, including explicit null and empty string handling.

Input: Name: Alice, Age: 30. Output: {"name": "Alice", "age": 30} Input: Name: Bob. Output: {"name": "Bob", "age": null}

Check: must contain at least 3 examples. Each example's output must strictly validate against [TARGET_SCHEMA]. Ensure examples demonstrate null for missing fields, not empty strings.

[NEGATIVE_EXAMPLES]

A set of counterexamples showing incorrect behavior, such as substituting empty strings for null or omitting fields.

Input: City: Paris. Incorrect Output: {"name": "", "age": 0} Input: City: Paris. Incorrect Output: {}

Check: must contain at least 2 counterexamples. Each must clearly violate a rule from [TARGET_SCHEMA] or the null-handling policy. Validate that they are labeled as incorrect.

[NULL_REPRESENTATION_POLICY]

An explicit instruction defining how to represent missing data, distinguishing between null, empty string, and field omission.

Use JSON null for any field where the value is not present in the input text. Never use an empty string "" to represent missing data. All fields defined as required in the schema must be present in the output object.

Check: must be a non-empty string. Policy must explicitly define the difference between null, "", and field absence. Confirm it aligns with the [TARGET_SCHEMA].

[CONFIDENCE_THRESHOLD]

A float between 0.0 and 1.0. If the model's confidence in an extracted value is below this threshold, the value should be set to null.

0.7

Check: must be a float between 0.0 and 1.0. If not provided, default to 0.0. A value of 0.0 disables confidence-based nulling.

[OUTPUT_FORMAT]

The required format for the final output, typically a strict JSON mode instruction.

You must respond with a single valid JSON object and nothing else. Do not include any explanatory text.

Check: must be a non-empty string. Should explicitly forbid markdown fences or extra text. This instruction is critical for preventing wrapper text around the JSON.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the null-handling prompt into a production extraction pipeline with validation, retries, and observability.

The null-handling demonstration prompt is designed to sit inside a larger extraction pipeline, typically after an initial extraction attempt and before downstream ingestion. Its job is narrow: take a raw model output that may contain ambiguous empty values and normalize it into a schema where null, empty string "", and missing keys have explicit, consistent meanings. Wire this prompt as a post-processing step, not as the primary extraction prompt. The primary extraction should attempt to populate all fields; this prompt handles the cleanup and disambiguation of missing or empty data.

Pipeline placement and invocation: Call this prompt after your primary extraction step returns a JSON object. Pass the raw extraction output as [EXTRACTION_OUTPUT] and your target schema with nullability annotations as [OUTPUT_SCHEMA]. Include [FIELD_DEFINITIONS] that specify, per field, whether the field is required, nullable, or has a default value. The model should receive few-shot examples that demonstrate the exact null representation your downstream systems expect—typically JSON null for unknown values, empty string "" only when the source explicitly contains an empty value, and omitted keys only when the schema marks them as optional and truly absent. Validation layer: After the prompt returns, run a schema validator that checks: (1) all required fields are present, (2) no field contains a placeholder like "N/A" or "missing" unless explicitly allowed, (3) null values appear only in nullable fields, and (4) empty strings appear only where semantically correct. If validation fails, retry once with the validation error message appended to the prompt as [PREVIOUS_ERROR]. If the second attempt fails, route to a human review queue with the original extraction, both attempts, and the validation errors logged.

Model choice and configuration: Use a model with strong instruction-following and JSON output capabilities. Set temperature=0 to minimize variance in null representation. Enable structured output mode if your provider supports it, binding the response to your target schema directly. Logging and observability: Log every invocation with: the input extraction, the normalized output, validation pass/fail status, retry count, and any human review escalation. Track metrics on null-field frequency, empty-string vs null confusion rate, and retry rate. These metrics will surface when your upstream extraction model changes behavior or when input data distributions shift. What to avoid: Do not use this prompt as a general-purpose data cleaner—it is specifically for null and empty-value disambiguation. Do not skip the validation layer; silent null-meaning errors corrupt downstream analytics and are hard to detect without explicit checks. Do not retry more than twice; after two failures, the ambiguity is likely in the source data itself and requires human judgment.

IMPLEMENTATION TABLE

Expected Output Contract

Validation rules for the null handling demonstration prompt. Use this contract to test whether the model correctly distinguishes null, empty string, and missing fields after few-shot training.

Field or ElementType or FormatRequiredValidation Rule

[EXTRACTED_ENTITY]

object

Top-level object must be present and parse as valid JSON

[EXTRACTED_ENTITY].name

string | null

Must be null when input provides no name; must not default to empty string

[EXTRACTED_ENTITY].email

string | null

Must be null when input provides no email; empty string is a validation failure

[EXTRACTED_ENTITY].phone

string | null

May be omitted entirely when input provides no phone; null is acceptable if present

[EXTRACTED_ENTITY].address

object | null

Must be null when input provides no address; must not be an empty object {}

[EXTRACTED_ENTITY].address.street

string | null

Must be null when parent address is null; must not be empty string when address is present

[EXTRACTED_ENTITY].confidence

number

Must be between 0.0 and 1.0; lower confidence expected when fields are null due to missing data

[EXTRACTED_ENTITY].missing_fields

array of strings

Must list every top-level field that was null or omitted due to missing input data

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when teaching null handling through few-shot examples, and how to prevent silent data corruption in production extraction pipelines.

01

Silent Empty String Substitution

What to watch: The model substitutes an empty string "" for a missing value instead of using an explicit null representation like null or a sentinel such as "N/A". This corrupts downstream analytics that distinguish between 'no value' and 'empty value'. Guardrail: Include at least two few-shot examples where missing data is explicitly mapped to null. Add a post-processing validator that rejects empty strings for nullable fields and logs a schema violation.

02

Silent Field Omission

What to watch: The model omits a key entirely from the JSON output when the source data lacks a value, instead of including the key with a null value. This breaks strict schema consumers that expect every field to be present. Guardrail: Use a counterexample showing an incorrect output with a missing key, paired with the corrected output. Validate output with a JSON Schema that sets "required" on all fields and "type": ["string", "null"] on nullable ones.

03

Null vs. Empty String Conflation

What to watch: The model treats a present-but-empty value (e.g., a blank form field) identically to a truly missing value, losing the semantic distinction. Guardrail: Provide a dedicated few-shot example that contrasts an empty string input with a missing input, showing "value": "" versus "value": null in the output. Add an eval assertion that checks for this distinction on a known test case.

04

Inconsistent Null Representation Across Runs

What to watch: The model uses null, "null", "None", or "N/A" interchangeably for the same field across different inputs, making the output unqueryable. Guardrail: Define a single canonical null representation in the system prompt and reinforce it in every few-shot example. Use a regex-based output validator to flag any null-like string other than the canonical null JSON value.

05

Hallucinated Default Values for Missing Data

What to watch: The model invents plausible values (e.g., a generic date or a zero amount) for missing fields instead of leaving them null, especially when examples show fully populated records. Guardrail: Include a counterexample where a hallucinated value is explicitly marked as incorrect. Add a confidence score field in the output schema and set a low-confidence threshold that triggers human review for any populated field sourced from missing data.

06

Null Handling Drift with Complex Nested Objects

What to watch: Null handling is correct at the top level but breaks inside nested objects or arrays, where the model omits sub-fields or inserts empty objects {}. Guardrail: Ensure few-shot examples include at least one deeply nested object with multiple missing sub-fields. Use a recursive schema validator in the application layer that traverses the entire output tree to confirm every declared key is present with a valid value or explicit null.

IMPLEMENTATION TABLE

Evaluation Rubric

Run these checks on a golden dataset of at least 50 examples covering present, empty, missing, and ambiguous fields. Each row tests a specific failure mode common in null-handling prompts.

CriterionPass StandardFailure SignalTest Method

Null vs Empty String Distinction

Missing fields output null; present-but-empty fields output ""

Missing field outputs "" or empty field outputs null

Schema diff against ground truth for 20 mixed null/empty examples

Silent Field Omission Detection

All schema-defined fields appear in output even when value is null

Field key is absent from output JSON entirely

JSON key enumeration check; fail if any expected key is missing

Explicit Null Annotation

null appears as a JSON value, not the string "null" or "N/A"

Output contains string literal "null", "None", or "N/A" instead of JSON null

Type check on each field value; fail on string null-substitutes

Partial Input Completeness

All extractable fields populated; non-extractable fields set to null

Extractable field left as null or non-extractable field hallucinated with a value

Field-by-field comparison against annotated ground truth for 15 partial-input examples

Ambiguous Field Handling

Ambiguous fields output null with [CONFIDENCE] below threshold or trigger clarification flag

Ambiguous field receives a guessed value without confidence annotation

Confidence threshold check; fail if low-confidence field has value without [CONFIDENCE] metadata

Type Consistency Under Missing Data

Field type matches schema regardless of null/empty/present state

Null field changes type from string to object or array in output

Type assertion per field across all 50 examples; fail on type deviation

Array Field Null Handling

Empty array outputs []; missing array outputs null; single-item array wraps correctly

Missing array outputs [] or single-item array outputs unwrapped value

Array type and length check against ground truth for 10 array-field examples

Counterexample Resistance

Model rejects inputs that cannot produce valid output per refusal examples in prompt

Invalid input produces a hallucinated structured output instead of refusal or error marker

Pass 10 invalid inputs from counterexample set; fail if any returns valid schema without refusal flag

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a small set of 3-5 few-shot examples covering the most common null scenarios. Skip formal schema validation in the prompt; rely on a post-processing check in your script. Replace [OUTPUT_SCHEMA] with a simplified JSON structure showing only the fields you need.

Watch for

  • The model substituting empty strings "" for null when examples don't explicitly show the difference
  • Silent field omission when a field is missing from input—add a counterexample showing explicit null
  • Overly broad instructions causing the model to invent values for missing data instead of marking them null
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.