Inferensys

Prompt

Address Parsing and Standardization Prompt Template

A practical prompt playbook for extracting structured address components from free-text model outputs, designed for logistics and CRM teams who need clean, deduplicatable address records.
MLOps engineer reviewing model serving infrastructure on laptop, container orchestration visible, technical workspace.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for address parsing and standardization.

This prompt is designed for logistics, CRM, and data engineering teams that need to convert free-text address strings—often generated by upstream models or extracted from unstructured documents—into a clean, structured object with predictable fields. The primary job-to-be-done is post-generation repair and normalization: taking a messy, inconsistent address string and producing a valid, standardized record with components like street, city, region, postal code, and country. The ideal user is a developer or data pipeline operator who already has an address string but cannot trust its format, completeness, or field ordering. You should use this prompt when the address content is present but structurally unreliable, not when the address is entirely missing or must be verified against a ground-truth database.

This prompt is not a replacement for a dedicated address validation API (such as Google Maps, Smarty, or Lob). It does not verify that an address physically exists, correct wrong house numbers, or append missing postal codes from a reference dataset. It operates purely on the string provided. Use it when you need fast, schema-conformant structuring before ingestion into a CRM, shipping label generator, or customer record. Do not use it for legal proof of address, geocoding, or any workflow where an incorrect but well-formatted address could cause a material failure (e.g., mailing compliance, emergency services). In those cases, this prompt should feed into a human review step or a downstream verification API.

Before wiring this into production, define your canonical address schema and decide which fields are required versus optional. International addresses vary widely: some regions lack postal codes, others use provinces instead of states, and many place the building number after the street name. The prompt includes a [CONSTRAINTS] placeholder where you can inject locale-specific rules, field requirements, and formatting standards (e.g., ISO 3166 country codes, uppercase postal codes). If your pipeline handles multiple countries, consider routing to locale-specific prompt variants or including few-shot examples for each target format. Start with a small eval set of 50–100 real addresses from your system, including edge cases like PO boxes, rural routes, apartment designators, and non-Latin scripts, and measure field-level accuracy before scaling.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Address Parsing and Standardization prompt works, where it breaks, and the operational preconditions required before putting it into a production pipeline.

01

Good Fit: CRM and Logistics Ingestion

Use when: Free-text address strings from model outputs, web forms, or customer service transcripts need to be split into structured components (street, city, region, postal code, country) before entering a system of record. Guardrail: Always validate the output against a postal code reference lookup before committing to the database.

02

Bad Fit: Legal Property Descriptions

Avoid when: The input is a legal lot description, metes-and-bounds text, or a deed record. These require geospatial survey logic, not NLP parsing. Guardrail: Route such inputs to a human reviewer or a specialized geocoding service rather than attempting LLM-based extraction.

03

Required Inputs: Contextual Country Hint

Risk: Without a country hint, the model will default to US formats, causing incorrect region/postal code parsing for international addresses. Guardrail: Always pass a [TARGET_COUNTRY] variable into the prompt template. If unknown, use a separate country detection prompt first.

04

Operational Risk: PO Box and Rural Route Handling

Risk: Models often misclassify PO Boxes as street addresses or drop rural route identifiers entirely, breaking delivery validation. Guardrail: Add explicit few-shot examples for PO Box, RR, and PMB formats in the prompt. Run a post-processing regex check to flag any address missing a street number that isn't a known PO Box pattern.

05

Operational Risk: Silent Truncation

Risk: Long, multi-line addresses can hit token limits, causing the model to silently drop apartment numbers or floor designations at the end of the string. Guardrail: Implement a pre-flight character count check. If the input exceeds a safe threshold, split the address or use a model with a larger context window. Log a warning if the output line count doesn't match the input line count.

06

Bad Fit: Real-Time Delivery Routing

Avoid when: The parsed address is the final step before a delivery driver is dispatched. A hallucinated postal code or a misclassified street type has immediate physical-world consequences. Guardrail: This prompt is a normalization tool, not a verification tool. Always pair it with an Address Validation API (e.g., USPS, Google Maps) as the authoritative gate before operational use.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt for extracting structured address components from free-text model outputs, ready to copy into your repair pipeline.

The prompt below takes a raw address string—often generated by an upstream model that produced free text instead of structured JSON—and parses it into a consistent, validated address object. It is designed for logistics and CRM repair loops where the upstream output is semantically correct but structurally unusable. The template uses square-bracket placeholders so you can inject your own input, output schema, constraints, and examples without rewriting the core instruction.

text
You are an address normalization engine. Your job is to parse a free-text address into a structured JSON object. You must not invent, infer, or hallucinate any field that is not present in the input. If a component is missing, set its value to null. If the input is ambiguous, flag it in the `warnings` array rather than guessing.

INPUT:
[INPUT]

OUTPUT_SCHEMA:
[OUTPUT_SCHEMA]

CONSTRAINTS:
[CONSTRAINTS]

EXAMPLES:
[EXAMPLES]

Return ONLY valid JSON. Do not include markdown fences, explanations, or any text outside the JSON object.

To adapt this template, replace [INPUT] with the raw address string from your upstream model. Set [OUTPUT_SCHEMA] to your target JSON structure—at minimum include street, city, region, postal_code, and country fields, plus a warnings array for ambiguity flags. Use [CONSTRAINTS] to specify locale-specific rules such as 'postal_code must match the format for [COUNTRY]' or 'PO Box addresses must populate the po_box field instead of street'. Provide 3–5 [EXAMPLES] that cover common cases, edge cases like rural routes and international formats, and failure cases where the model should return null fields with warnings. After copying the template, run it through your validation harness before deploying—address repair is high-stakes when downstream systems depend on correct routing, compliance checks, or customer communications.

IMPLEMENTATION TABLE

Prompt Variables

Required and optional inputs for the address parsing prompt. Validate each input before calling the model to prevent garbage-in-garbage-out failures in production pipelines.

PlaceholderPurposeExampleValidation Notes

[RAW_ADDRESS]

Free-text address string from model output, user input, or upstream system

123 Main St Apt 4B Springfield IL 62701

Must be non-empty string. Check for null, empty, or whitespace-only inputs. Reject inputs over 500 characters to prevent prompt stuffing.

[TARGET_COUNTRY]

ISO 3166-1 alpha-2 country code to bias parsing rules

US

Must match exactly 2 uppercase letters. Validate against allowed country list. Use null if country is unknown or multi-country parsing is required.

[OUTPUT_SCHEMA]

JSON schema or field list defining expected output structure

{"street_number": "string", "street_name": "string", "unit": "string|null", "city": "string", "state": "string", "postal_code": "string", "country": "string"}

Must be valid JSON schema or explicit field enumeration. Reject schemas with circular references. Validate that required fields match downstream consumer expectations.

[ADDRESS_FORMAT_HINTS]

Optional hints about expected address format conventions for the target locale

USPS standard, include ZIP+4 if present, PO Box format: PO BOX [number]

Allow null or empty string. If provided, must be plain text under 300 characters. Do not allow injection of conflicting instructions that override schema requirements.

[CONFIDENCE_THRESHOLD]

Minimum confidence score (0.0-1.0) required to return a parsed field without flagging for review

0.8

Must be a float between 0.0 and 1.0 inclusive. Default to 0.7 if not provided. Values below 0.5 will produce excessive review flags; values above 0.95 may suppress valid parses.

[MAX_REVIEW_FIELDS]

Maximum number of fields allowed to fall below confidence threshold before entire record is escalated

3

Must be a positive integer. Default to 3. Set to 0 to escalate any low-confidence field. Set higher for batch processing where partial results are acceptable.

[ALLOWED_COUNTRIES]

Whitelist of ISO country codes the parser should accept; addresses outside this list are flagged

["US", "CA", "GB", "AU"]

Must be a JSON array of 2-letter uppercase strings or null. If null, all countries are allowed. Validate each code against ISO 3166-1. Empty array means reject all addresses.

[PO_BOX_HANDLING]

Instruction for how to treat PO Box addresses: accept, flag, reject, or convert to street address

flag

Must be one of: accept, flag, reject, convert. Default to flag. Reject is appropriate for physical delivery use cases. Convert should only be used when a verified street address mapping exists.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the address parsing prompt into a production application with validation, retries, and quality gates.

Integrating the address parsing prompt into an application requires more than a single API call. The harness must handle malformed inputs, validate the model's output against a strict schema, and decide when to retry, repair, or escalate. For address standardization, the most common failure modes are missing required fields (like postal code or country), hallucinated components not present in the input, and format violations that break downstream geocoding or label printing systems. A robust harness treats the prompt as one step in a pipeline that includes pre-processing, post-validation, and a retry loop with escalating interventions.

Start by defining a strict output schema. The prompt should return a JSON object with fields such as street_number, street_name, unit_type, unit_number, city, state_province, postal_code, country, and a confidence score per field. In your application code, validate this output immediately: check that country is a valid ISO 3166-1 alpha-2 code, that postal_code matches a regex for the claimed country, and that required fields like city and street_name are non-empty strings. If validation fails, do not discard the output. Instead, construct a repair prompt that includes the original input, the failed output, and the specific validation errors. This repair prompt should instruct the model to fix only the invalid fields while preserving the valid ones. Limit repair attempts to two retries. If the output still fails validation after two repair passes, log the record for human review and return a partial result with an unresolved_fields array so the downstream system can decide whether to proceed with incomplete data.

For high-throughput pipelines processing thousands of addresses, batch the inputs and run validation in parallel. Use a model with low latency for the initial parse (such as a smaller fine-tuned model or a fast API endpoint) and reserve a more capable model for the repair step on the small fraction of records that fail validation. Log every parse attempt—including the raw model response, validation errors, and repair outcomes—so you can measure field-level accuracy, hallucination rates, and repair success over time. This log becomes your evaluation dataset for testing prompt changes. Before deploying any prompt update, replay a sample of production failures through the new prompt and compare repair rates and accuracy against the current baseline. If the new prompt introduces regressions on international addresses or PO box handling, revert and iterate before releasing.

PRACTICAL GUARDRAILS

Common Failure Modes

Address parsing is brittle because free-text addresses vary wildly across regions, formats, and user behaviors. These failure modes surface most often in production when the model encounters ambiguous locality names, non-standard abbreviations, or cultural address conventions it wasn't explicitly constrained to handle.

01

Locality vs. Administrative Area Confusion

What to watch: The model swaps city and province/state fields, especially in countries where administrative divisions aren't hierarchical (e.g., UK counties, Japanese prefectures, or Australian suburbs). A city name may also be a valid region name, causing the parser to misclassify it. Guardrail: Provide a country-specific field precedence map in the prompt. Validate output against a postal reference lookup for the claimed country before accepting the parse.

02

PO Box and Non-Street Address Misclassification

What to watch: The model forces a PO Box, Private Bag, or military address into street number and street name fields, inventing a fake street structure. This corrupts downstream geocoding and shipping validation. Guardrail: Add an explicit address_type enum field (e.g., street, po_box, rural_route) in the output schema. Run a post-extraction check: if address_type is po_box, the street_number and street_name fields must be null.

03

International Postal Code Format Drift

What to watch: The model outputs a postal code in the wrong format for the claimed country (e.g., a US ZIP+4 for a Canadian address, or a UK outward code without the space). This breaks shipping label generation and tax calculation. Guardrail: Include a country-to-postal-code-regex map in the prompt constraints. Add a post-processing validator that rejects any postal_code that fails the regex for the extracted country field and triggers a repair retry.

04

Over-Aggressive Abbreviation Expansion

What to watch: The model expands abbreviations that should remain abbreviated per postal standards (e.g., expanding "St" to "Street" when "St" is the official postal form, or expanding "Mt" to "Mount" incorrectly). This creates mismatches with official address databases. Guardrail: Provide a list of postal-safe abbreviations that must not be expanded. Instruct the model to prefer the USPS or local postal authority abbreviation table. Validate output against a canonical abbreviation list for the target country.

05

Multi-Line Address Concatenation Errors

What to watch: When a free-text address spans multiple lines, the model incorrectly merges address line 2 (apartment, suite, floor) into the street name or city field, or drops it entirely. This causes delivery failures for multi-unit buildings. Guardrail: Require a separate address_line_2 field in the output schema. Use few-shot examples that demonstrate correct splitting of unit, floor, and building identifiers from the primary street line. Test with addresses containing commas, newlines, and inconsistent delimiters.

06

Country Name vs. Code Inconsistency

What to watch: The model outputs a full country name in one field and an ISO code in another, but they don't match (e.g., country: "United Kingdom", country_code: "US"). This breaks downstream systems that rely on code-based routing. Guardrail: Constrain the output to ISO 3166-1 alpha-2 codes only. Add a validation step that checks internal consistency: if both country and country_code are present, they must resolve to the same ISO entry. On mismatch, discard the full name and trust the code, or escalate for human review.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to evaluate the quality of the address parsing and standardization prompt before shipping. Each criterion includes a pass standard, a failure signal, and a test method to integrate into your CI/CD or manual QA process.

CriterionPass StandardFailure SignalTest Method

Field Completeness

All required fields (street, city, region, postal_code, country) are present and non-null for a standard input.

Missing required fields or null values for a complete input address.

Schema validation against the [OUTPUT_SCHEMA] with a golden set of 50 complete addresses.

Component Accuracy

Street number, name, and type are correctly parsed into the correct sub-fields for USPS-standard addresses.

Street number placed in the street name field, or street type misclassified as a unit designator.

Exact string match comparison against pre-labeled ground truth for 100 addresses.

PO Box Handling

PO Box addresses are correctly identified and parsed into the po_box field, not the street field.

PO Box information is incorrectly placed in the street_number or street_name fields.

Unit test with 20 PO Box variants (e.g., 'P.O. Box 123', 'PO BOX 456').

International Format Variance

Addresses from 5+ countries are parsed with correct country-specific field mapping and no data loss.

A non-US address is forced into a US-centric field structure, losing information like district or province.

Test harness with a diverse international address dataset, checking for field misuse and truncation.

Secondary Unit Designator

Apartment, suite, and unit numbers are correctly extracted into the secondary_unit field.

Unit information is appended to the street_name or placed in the city field.

Validation script that checks the secondary_unit field for expected values from 30 multi-unit addresses.

Postal Code Validation

Postal code format matches the regex pattern for the specified country.

A US ZIP+4 code is truncated, or a UK postcode is formatted without the space.

Regex validation per country code on the postal_code field, tested against 50 international codes.

Country Standardization

Country is output as the ISO 3166-1 alpha-2 code.

Country is output as a full name, a common abbreviation (e.g., 'UK'), or is null.

Check that the country field is exactly 2 uppercase letters and exists in the ISO 3166-1 list.

Hallucination Resistance

No fields are invented for an incomplete input; missing optional components are null.

A zip code or city is hallucinated for an input that only contains a street and country.

Test with 20 intentionally incomplete addresses and assert that only provided fields are populated.

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a simple JSON schema. Use a single model call with no retries. Accept the output as-is for manual review. Focus on getting the field extraction logic right before adding validation layers.

code
Parse the following free-text address into structured components:
[RAW_ADDRESS_TEXT]

Return JSON with these fields: street, city, region, postal_code, country.

Watch for

  • Missing schema checks leading to downstream parsing failures
  • Overly broad instructions that produce narrative instead of JSON
  • No handling for PO boxes, rural routes, or international formats
  • Silent null fields when the model can't parse a component
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.