Enhancing Input Quality Before Prompting
This lesson describes deterministic, service-based and FM-based enhancements that improve noisy, inconsistent or ambiguous input before it reaches the main prompt, often more cheaply than switching to a larger model.
Learning outcomes
After completing this lesson, you will be able to:
- Normalize input with Lambda.
- Extract structure with Amazon Comprehend.
- Reformat input with a smaller Bedrock model.
Normalizing with Lambda
Not every improvement to input quality needs a model. Deterministic clean-up, performed by ordinary code, is fast, cheap and predictable, so it should be applied first. A Lambda function can strip HTML markup, email signatures, legal disclaimers and quoted earlier replies; normalise whitespace and Unicode characters; standardise dates to ISO 8601 and units and currencies to one format; expand known abbreviations; and truncate inputs to a token budget.
These steps have measurable benefits. Removing boilerplate reduces the number of input tokens, and therefore cost and latency, sometimes substantially for email threads. Consistent formats make outputs more consistent, because the model does not have to interpret each variation. And because the same input always produces the same normalised text, caches keyed on the input work more effectively. Model-based enhancement, such as rewriting unclear requests, is then reserved for problems that rules cannot solve.
The following diagram shows the input pipeline in front of the summary model.

Extracting structure with Amazon Comprehend
Free text from users and documents often contains facts that the application could use if they were identified explicitly. Amazon Comprehend provides natural language processing APIs that need no training: entity detection, which finds people, organisations, locations, dates and quantities; key phrase extraction; dominant language detection; sentiment analysis; PII detection; and toxicity detection. Because these are purpose-built models, they are faster, cheaper and more consistent than asking a foundation model to perform the same extraction.
When the built-in entity types are not enough, custom entity recognition and custom classification are trained on an organisation's own labelled examples to recognise domain-specific entities, such as product codes, or to assign domain-specific categories, such as the department a request belongs to.
Extracted entities can be added to the prompt as structured context ("Customer: Acme Ltd; Product: X200; Date: 2026-03-14"), stored as metadata for retrieval filters, or used to route the request. Language detection lets the application choose the right prompt and reply language.
Comprehend features
Reformatting with a Bedrock model
Some inputs need judgement to clean up rather than fixed rules, such as a rambling voice transcript or an email thread that covers several topics. A small, inexpensive Bedrock model can rewrite such input into a structured form, for example a summary with fields for the issue, the product and the requested action, before a larger model reasons over it. The larger model then works with shorter, clearer input, which improves its answers and reduces the number of expensive tokens it processes.
In conversations, query rewriting applies the same idea: a small model uses the conversation history to turn follow-up questions, such as "what about the other one?", into self-contained questions that retrieval and generation can handle without the history. Because model-based reformatting can change meaning, its output should be logged and spot-checked like any other model output.
The following table compares the three approaches.
| Approach | Strength | Example |
|---|---|---|
| Lambda normalisation | Deterministic, cheap, fast | Strip signatures, standardise dates |
| Amazon Comprehend | Managed NLP for entities, language, PII | Extract product and customer names |
| Small Bedrock model | Judgment-based restructuring | Turn a transcript into a structured issue summary |
Code or a model?
Inconsistent ticket summaries
A model summarises support emails inconsistently: it sometimes summarises the signature or an earlier quoted message, and dates appear in many formats.
The input, not the model, is the problem. A Lambda pre-processor removes signatures and quoted history and normalises dates; Comprehend extracts product and customer entities that are added as structured fields; and the summary prompt receives clean, structured input. Consistency improves without changing the model.
Which service detects entities, language and PII in text without any training?
Show answer
Amazon Comprehend.
Exam Tips
Remember for the exam
- Clean deterministically first with Lambda.
- Entities, language and PII without training: Comprehend.
- Judgment-based restructuring: a small Bedrock model.
- Rewrite follow-up questions into standalone queries.