Inferensys

Prompt

Smart Quote to Straight Quote Sanitization Prompt

A practical prompt playbook for using Smart Quote to Straight Quote Sanitization Prompt 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 Smart Quote to Straight Quote Sanitization Prompt.

This prompt is for developers and platform engineers whose code parsers, SQL engines, configuration loaders, or CLI tools choke on curly quotes (“ ” ‘ ’) that appear in model-generated text. The job-to-be-done is a deterministic character-level sanitization: convert all smart quotes and similar typographic characters into their ASCII straight-quote equivalents (" and ') without altering any other content. The ideal user is an integration engineer or backend developer who is piping model output into a system with a strict ASCII or Latin-1 contract and cannot afford parser failures, syntax errors, or silent data corruption caused by non-standard quote characters.

Use this prompt when the model output is structurally valid but contains typographic quotes that break a downstream parser. This is common when models generate JSON values, SQL string literals, shell commands, CSV fields, or code snippets where curly quotes are interpreted as syntax errors. The prompt is designed for post-generation repair, not for preventing the model from producing smart quotes in the first place. It assumes you have already received the output and need a reliable normalization step before the text enters a system that rejects non-ASCII quote characters. Do not use this prompt when the text requires locale-aware apostrophe handling (e.g., French or Italian elision where a curly apostrophe carries semantic meaning that should be preserved) without first adding explicit rules for those cases.

Before wiring this prompt into a production pipeline, define your eval criteria clearly. A successful sanitization means every and becomes ', every and becomes ", and no other characters are modified. Common failure modes include false-positive corrections where a curly quote inside a code comment or a string literal that intentionally contains a typographic quote is flattened, or false negatives where uncommon Unicode quote variants like ‹› or «» are left untouched. If your downstream system has additional constraints—such as rejecting all non-ASCII characters—pair this prompt with an ASCII-only fallback prompt. For high-risk pipelines where quote corruption could cause SQL injection or shell command alteration, always run a diff check between the original and sanitized output and log any changes before the sanitized text is used.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Smart Quote to Straight Quote Sanitization Prompt works and where it introduces unacceptable risk.

01

Good Fit: Pre-Parser Sanitization

Use when: model outputs feed directly into code parsers, SQL engines, JSON decoders, or config loaders that reject non-ASCII quotes. Guardrail: run sanitization as a post-generation, pre-ingestion step in the API gateway or integration layer, not inside the model prompt itself.

02

Bad Fit: Locale-Aware Linguistic Text

Avoid when: output is destined for human readers in languages where curly quotes carry semantic or typographic meaning (e.g., French guillemets, German „ “). Guardrail: use locale-aware normalization or skip sanitization entirely for user-facing text surfaces.

03

Required Input: Quote-Delimited Strings

Use when: the input contains text with identifiable quote characters that must be converted. Guardrail: validate that the input actually contains smart quotes before invoking the prompt to avoid unnecessary processing and potential false-positive corrections on straight quotes.

04

Operational Risk: Apostrophe False Positives

Risk: straightening curly apostrophes in possessives or contractions (e.g., "it's" → "it's") is usually safe, but locale-specific apostrophe rules (e.g., Hawaiian ʻokina, Ukrainian apostrophe) can cause data corruption. Guardrail: add an eval check for known false-positive patterns and maintain a skip-list of terms that must preserve the original character.

05

Operational Risk: Nested Encoding Artifacts

Risk: if the input has already been double-encoded (e.g., “ HTML entities), straightening the underlying character may break downstream HTML rendering. Guardrail: detect and decode HTML entities before quote sanitization, or run a pre-check for entity-encoded quotes and route to an entity-decoding prompt first.

06

Operational Risk: Silent Data Corruption

Risk: a blanket find-and-replace approach can corrupt data where curly quotes are intentional delimiters in structured fields. Guardrail: log every replacement with position and original character for auditability, and add a dry-run mode that reports changes without mutating the payload.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt for converting smart quotes and other typographic characters into ASCII-safe straight quotes for code parsers, SQL engines, and config loaders.

This prompt template is designed to be dropped directly into your post-processing pipeline. It instructs the model to act as a precise text sanitizer, converting only typographic quotation marks and apostrophes into their ASCII equivalents while preserving all other content, including intentional formatting, code blocks, and locale-specific punctuation. The template uses square-bracket placeholders for the input text and any optional constraints you need to pass at runtime.

text
Sanitize the following text by converting all typographic (curly/smart) quotation marks and apostrophes to standard ASCII straight quotes. Follow these rules exactly:

1. Convert left double quotes (“) to straight double quotes (")
2. Convert right double quotes (”) to straight double quotes (")
3. Convert left single quotes (‘) to straight single quotes (')
4. Convert right single quotes (’) to straight single quotes (')
5. Do NOT modify any other characters, including:
   - Standard straight quotes and apostrophes already present
   - Code blocks, inline code, or any text inside backticks
   - Intentional typographic characters like primes (′ ″) or angle quotes (« »)
   - Locale-specific punctuation such as German low quotes („ “)
   - Any non-quote characters, whitespace, or line endings
6. Return ONLY the sanitized text with no additional commentary, explanation, or wrapping

[INPUT]

[CONSTRAINTS]

To adapt this prompt, replace [INPUT] with the raw text from your model's output. Use [CONSTRAINTS] to pass any additional rules at runtime, such as preserving specific quote styles for certain locales or excluding particular sections from conversion. If you need to handle locale-aware apostrophes (e.g., French elision, Italian apostrophes), add those as explicit exceptions in the constraints block. For high-risk contexts like SQL query generation or code that will be executed, always validate the output through a secondary ASCII-only character filter before ingestion.

IMPLEMENTATION TABLE

Prompt Variables

Required and optional inputs for the Smart Quote to Straight Quote Sanitization Prompt. Validate each input before calling the model to prevent downstream parser failures.

PlaceholderPurposeExampleValidation Notes

[INPUT_TEXT]

The raw text containing smart quotes, curly apostrophes, or other non-ASCII quotation marks that must be converted to straight ASCII equivalents.

"It’s a ‘test’ of the “system”."

Must be a non-empty string. Check for presence of Unicode quotation characters (U+2018, U+2019, U+201C, U+201D) before invoking the prompt. If none are detected, skip the model call to save cost.

[LOCALE]

The language or region context for disambiguating apostrophe usage. Critical for distinguishing possessive apostrophes from single-quote delimiters in languages like French or Italian.

"en-US"

Must be a valid BCP 47 language tag. Defaults to "en-US" if not provided. Use "auto" to let the model infer locale from surrounding text, but expect lower accuracy on mixed-language inputs.

[PRESERVE_EMPHASIS]

A boolean flag indicating whether the model should attempt to preserve the semantic intent of smart quotes used for emphasis or irony in informal text.

Must be true or false. When true, the model may add lightweight markup like asterisks around previously smart-quoted phrases. When false, all quotes become literal straight quotes with no emphasis preservation.

[OUTPUT_FORMAT]

The desired output structure. Controls whether the model returns only the sanitized text or a detailed change log.

"text-only"

Must be one of "text-only" or "with-changes". "text-only" returns the cleaned string. "with-changes" returns a JSON object with "sanitized_text" and "replacements" array listing each substitution made.

[ESCAPE_CONTEXT]

The target system context for any additional escaping required after sanitization. Prevents double-escaping when the output feeds into SQL, JSON, or HTML.

"json-string"

Must be one of "plain-text", "json-string", "sql-literal", "html-content", or null. When set, the model applies context-appropriate escaping after quote sanitization. Use null for raw text output.

[FAILURE_MODE]

The behavior when the model cannot confidently resolve an ambiguous quote. Controls whether the model makes a best guess or flags the ambiguity for human review.

"flag"

Must be "best-guess" or "flag". "best-guess" silently resolves ambiguity. "flag" wraps ambiguous segments in [[? ... ?]] markers for downstream review. Use "flag" for high-stakes contexts like legal or medical text.

[MAX_LENGTH]

The maximum character length of the input text. Used to decide whether chunking is required before processing.

5000

Must be a positive integer. If [INPUT_TEXT] exceeds this value, the caller should split the text into overlapping chunks before invoking the prompt. The prompt itself does not perform chunking.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the smart quote sanitization prompt into a production application with validation, retries, and monitoring.

The smart quote sanitization prompt is designed to be a post-processing repair step in a pipeline, not a standalone user-facing feature. It should sit immediately after the primary model call and before any parser, SQL engine, config loader, or serialization step that is known to choke on curly quotes. The prompt expects a single string input ([INPUT]) and returns a sanitized string. Do not use this prompt on user-facing display text where typographic quotes are intentional and desirable—it is strictly for machine-to-machine boundaries.

Integration pattern: Wrap the prompt call in a lightweight function that accepts the raw model output string and returns the sanitized string. The function should: (1) Check if the input contains any curly quote characters (\u2018, \u2019, \u201C, \u201D) before calling the LLM—if none are present, return the input immediately to avoid unnecessary latency and cost. (2) Call the sanitization prompt with the input. (3) Validate the output by confirming no curly quotes remain. (4) If curly quotes persist, retry once with an explicit error message appended to the prompt context. (5) If the retry also fails, log the failure with the original and sanitized strings, and fall back to a deterministic regex replacement (text.replace(/[\u2018\u2019]/g, "'" ).replace(/[\u201C\u201D]/g, '"')) as a safety net. The LLM path handles locale-aware apostrophe disambiguation (e.g., preserving ' in contractions vs. replacing opening/closing single quotes); the regex fallback is a blunt instrument that trades nuance for reliability.

Model choice and latency: This is a low-complexity string transformation task. Use the smallest, fastest, cheapest model available in your stack that can follow the instruction reliably—typically a lightweight model like GPT-3.5 Turbo, Claude Haiku, or an open-weight 7B-class model. Do not route this to a large reasoning model. Set a short timeout (2-3 seconds) and treat timeouts as a signal to fall back to the deterministic regex path. Logging and observability: Log every invocation with: input length, whether curly quotes were detected, whether the LLM path or regex fallback was used, latency, and a boolean sanitization_success flag. This lets you monitor how often the LLM path is actually needed and whether the regex fallback is carrying too much load. Testing: Before deploying, run a golden test set of 50+ strings covering: mixed curly and straight quotes, nested quotes, locale-specific apostrophes (French l'école, Italian dell'arte), empty strings, strings with no quotes, and strings with only straight quotes. Assert that the output contains zero curly quotes and that legitimate apostrophes in contractions are preserved as straight single quotes, not removed or replaced with spaces.

IMPLEMENTATION TABLE

Expected Output Contract

Define the exact shape of the sanitized output so that downstream parsers, SQL engines, and config loaders can consume it without failure. Use this contract to validate the model's response before passing it to the next system.

Field or ElementType or FormatRequiredValidation Rule

sanitized_text

string

Must contain only ASCII straight single quotes (U+0027) and double quotes (U+0022). No curly/smart quotes (U+2018, U+2019, U+201C, U+201D) or other non-ASCII quote characters allowed.

replacement_log

array of objects

If present, each object must have fields: position (integer, zero-indexed), original_char (string, single Unicode code point), replacement_char (string, single ASCII code point). Array must be empty if no replacements were made.

locale_override_applied

boolean

Must be true if a locale-specific rule was used (e.g., preserving apostrophe in French elision like l'homme). Must be false if only default ASCII conversion was applied. Cannot be null.

ambiguous_apostrophe_count

integer

Count of characters that could be either an apostrophe or a single closing quote. Must be >= 0. Used by the harness to decide if human review is needed for high counts.

processing_notes

string or null

If non-null, must be a plain-text string explaining any edge cases encountered (e.g., 'Preserved 3 French apostrophes', 'Detected mixed quote styles in code block'). Must not exceed 500 characters.

input_hash

string

SHA-256 hex digest of the original input text. Must be exactly 64 lowercase hexadecimal characters. Used to verify that the sanitized output corresponds to the correct input in async pipelines.

model_version

string

Identifier for the model or prompt version that produced this output. Must match the pattern [PROMPT_NAME]/v[MAJOR].[MINOR] (e.g., smart-quote-sanitizer/v1.2). Used for traceability and rollback decisions.

PRACTICAL GUARDRAILS

Common Failure Modes

Smart quote sanitization seems simple until it breaks a parser, corrupts a locale-specific string, or mangles legitimate curly quotes in code. These are the most common production failure modes and how to prevent them.

01

Locale-Aware Apostrophe Corruption

What to watch: The prompt blindly replaces all right single quotes (U+2019) with straight apostrophes, breaking legitimate contractions in French (l'été), Italian, or Catalan where the character is grammatically required. Guardrail: Add a locale-awareness rule in the prompt that preserves apostrophes when the surrounding characters match known word patterns for the target language. Test with a multilingual golden set before deployment.

02

Code and String Literal Breakage

What to watch: The model output contains smart quotes inside code snippets, JSON string values, or SQL literals. The sanitization prompt replaces them with straight quotes, but the replacement creates unescaped quotes that break the enclosing string delimiter. Guardrail: Add a pre-processing step that detects code blocks or string literal boundaries and applies context-appropriate escaping (e.g., backslash-escaping) rather than naive character replacement. Validate with a parser round-trip test.

03

False-Positive Straight Quote Conversion

What to watch: The prompt is over-aggressive and converts intentionally placed straight quotes that are already correct—such as inch marks (5'11"), feet notation, or ditto marks—into something else, or flags them unnecessarily. Guardrail: Constrain the prompt to target only known smart quote Unicode ranges (U+2018, U+2019, U+201C, U+201D) and explicitly instruct it to leave existing ASCII straight quotes untouched. Add eval assertions that count false-positive modifications.

04

Nested Quote Delimiter Confusion

What to watch: The model output contains nested quotation patterns like "He said, 'hello'" where smart double and single quotes are mixed. The sanitization prompt flattens them all to straight quotes, making it impossible to distinguish opening from closing delimiters. Guardrail: Include few-shot examples in the prompt showing how to preserve quote pairing semantics. For complex nesting, route to a parser-aware repair step rather than relying on character-level replacement alone.

05

Streaming Output Mid-Character Corruption

What to watch: In streaming or chunked response pipelines, a multi-byte smart quote character (e.g., U+201C encoded as 3 bytes in UTF-8) is split across two chunks. The sanitization step sees a partial byte sequence and either drops the character, inserts a replacement character (U+FFFD), or corrupts adjacent bytes. Guardrail: Buffer streaming chunks on UTF-8 character boundaries before running sanitization. Validate with a streaming simulator that injects chunk boundaries at every possible byte offset.

06

Downstream System Double-Encoding

What to watch: The prompt correctly converts smart quotes to straight quotes, but a downstream serialization layer (e.g., JSON.dumps, XML escape, or HTML entity encoding) re-escapes the straight quotes, producing " or " that the final consumer cannot parse. Guardrail: Add an integration test that runs the full pipeline—prompt output through serialization to final consumer—and asserts that the end-to-end payload is parseable. Document the expected encoding state at each handoff boundary.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the Smart Quote to Straight Quote Sanitization Prompt before deploying it in a production pipeline. Each criterion targets a known failure mode for this specific sanitization task.

CriterionPass StandardFailure SignalTest Method

Curly Double Quote Replacement

All occurrences of “ and ” are replaced with straight double quotes (")

Any curly double quote remains in the output string

Scan output with regex /[\u201c\u201d]/; count must be zero

Curly Single Quote Replacement

All occurrences of ‘ and ’ are replaced with straight single quotes (')

Any curly single quote remains in the output string

Scan output with regex /[\u2018\u2019]/; count must be zero

Locale-Aware Apostrophe Preservation

Contractions like "don't" and "it's" use straight single quotes, not removed or replaced with spaces

Apostrophe is deleted ("dont") or replaced with a space ("don t")

Assert that known contractions from a test set retain a straight single quote in the correct position

False-Positive Correction Avoidance

Straight quotes that were already correct in [INPUT] remain unchanged

A pre-existing straight quote is doubled, escaped, or removed

Diff [INPUT] and output; all pre-existing straight quotes must be identical in position and character

Non-Quote Character Preservation

All other characters (letters, numbers, punctuation, whitespace) are identical to [INPUT]

Any character other than curly quotes is altered, added, or removed

Normalize both strings by removing all quote characters; the resulting strings must be identical

Empty String Handling

An empty [INPUT] string returns an empty string without error

Output is null, an error message, or a string containing unexpected characters

Pass an empty string; assert output is exactly "" (zero-length string)

High-Volume Throughput

A 10KB input with mixed curly and straight quotes is processed without truncation or timeout

Output is truncated, or processing exceeds a reasonable time threshold (e.g., 2 seconds)

Generate a 10KB test string with quotes at random positions; assert output length equals input length and completes within time limit

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a simple string input. Use a lightweight script that sends the prompt to a frontier model and checks if the output contains any Unicode curly quote characters (\u2018, \u2019, \u201c, \u201d). No schema validation or retry logic needed.

code
Sanitize all smart quotes in [INPUT_TEXT] to straight ASCII quotes.
Replace ‘ and ’ with ' and “ and ” with ".
Return only the sanitized text.

Watch for

  • Locale-aware apostrophes in contractions (e.g., French l’homme) being incorrectly converted when they should be preserved
  • False positives where straight quotes inside code blocks or string literals are accidentally modified
  • No handling of edge cases like prime marks (, ) used in measurements
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.