Lesson 5 of 6 Evaluating Generative AI

Checking Generative Output for Quality, Safety and Bias

This lesson explains how generative AI outputs are checked for content quality, safety and bias before release, which the exam guide groups under AI evaluation.

Learning outcomes

After completing this lesson, you will be able to:

  • Validate content quality such as format and tone.
  • Measure toxicity and robustness.
  • Detect bias in generated output with counterfactual tests.

Content quality validation

Content quality covers several properties. Format includes valid JSON, required sections and length limits. Language and tone include brand voice, reading level and responding in the correct language. Accuracy is measured against sources, and policy compliance covers prohibited advice and required disclaimers.

Different checks suit different properties: programmatic checks handle format and length cheaply and reliably, while LLM judges and guardrails handle tone and policy. Outputs that fail can be regenerated, repaired automatically or blocked before they reach users.

Sort into groups

Check the output

Exam skills 2.3.9

Decide whether each check is best done by code or needs a judgement-based evaluation.

Log in to try this activity Interactive activities are free with an account.

Safety and toxicity

Amazon Bedrock programmatic evaluations include toxicity metrics and robustness metrics, which measure whether small changes to the input, such as typos, change the output, and judge-based metrics include harmfulness. Red-teaming with adversarial prompts tests whether the model can be pushed into unsafe output or manipulated through prompt injection.

At run time, Amazon Bedrock Guardrails enforce safety policies on every request and response. The rate at which guardrails intervene is itself a useful quality signal: a rising rate can indicate a change in user behaviour, an attack or a regression in the model or prompt.

True or false

Safety checks

Exam skills 2.3.9 · 4.3.9

Check how generated content is tested for safety.

Log in to try this activity Interactive activities are free with an account.

Bias detection in generative output

Generative bias appears as stereotypes, unequal quality across groups or different recommendations for equivalent requests. Detect it with counterfactual (paired) prompts that differ only in a demographic attribute, such as a name or pronoun, and compare outputs and scores. SageMaker Clarify foundation model evaluations (built on the open-source fmeval library) and Bedrock evaluations include prompt stereotyping datasets that measure whether a model prefers stereotypical sentences. The following table summarises the checks.

CheckMethod
Format and lengthProgrammatic validation (schema, regex, length)
Tone and policyLLM judge with rubric, guardrail denied topics
Toxicity and harmToxicity metrics, harmfulness judge, Guardrails content filters
RobustnessPerturbed prompts; robustness metrics
Stereotyping and unequal treatmentPaired prompts, Clarify FM evaluations, stereotyping datasets

The following diagram shows the checks used to find biased language in an HR assistant's drafts and their effect.

Checking the HR assistant for biased language. Paired prompts that differ only in the hiring manager's wording are compared, a Clarify FM evaluation measures prompt stereotyping, and a judge flags exclusionary phrases against a rubric. Age-related phrasing appeared in 7% of drafts; a revised system prompt and a guardrail word filter brought it below 0.5%.
Bar lengths are proportional.
Worked example

A job-description assistant

An HR assistant drafts job descriptions. Before launch, the team checks for biased language and unequal quality.

  • Generate descriptions for 200 roles twice, with prompts that differ only in the hiring manager's stated preference wording, and compare gendered-language counts.
  • Run a Clarify FM evaluation for prompt stereotyping on the chosen model.
  • Use a judge to flag exclusionary phrases ("young and energetic") against a rubric; add a guardrail word filter for known terms.

The checks find age-related phrasing in 7% of drafts; a revised system prompt and a word filter bring it below 0.5%. Measuring only fluency or ROUGE would never have revealed this problem.

Check yourself

How do paired prompts reveal bias?

Show answer

Prompts that differ only in a group attribute, such as a name, should get equivalent responses; differences show stereotyping or unequal treatment.

Exam Tips

Remember for the exam

  • Validate format and length programmatically before release.
  • Paired prompts reveal stereotyping and unequal treatment.
  • Clarify FM evaluations and Bedrock evaluations measure stereotyping and toxicity.
  • Red-team with adversarial prompts before launch.
  • Guardrail intervention rates are a production quality signal.