New cohort: Agentic AI & LLM Engineering remote internship. Limited seats.Apply now
Lesson 03 of 21 18 minFree

Using Generative AI Responsibly

The real risks of generative AI apps, the principles that guide responsible AI, and the four layers of protection you can build into every product.

By the end of this lesson you will be able to:

  • Name the main harms a generative AI app can cause.
  • Explain six principles of responsible AI in plain words.
  • Apply four layers of mitigation: model, safety system, system message and user experience.
  • Write code that removes personal data before it reaches a model.

Why this comes before building

It is tempting to jump straight to coding. But an AI study buddy talks to children and teenagers, sometimes late at night, sometimes when they are stressed before exams. One confident wrong answer, one insensitive reply or one leaked phone number can hurt a real person and destroy trust in the product.

Responsible AI is not a legal checkbox at the end. It is a set of design decisions you make from the first day.

What can go wrong?

1. Ungrounded or wrong answers

As we saw in Lesson 1, LLMs predict likely text, not verified truth. A model might invent a formula, a historical date or a "source" that doesn't exist. In education that is especially harmful, because the student came to learn the right answer.

  1. Who was the first person to land on Mars?
  2. The first person to land on Mars was Commander Alex Rivera in 2031, during the Ares IV mission.
  3. ✗ No human has landed on Mars. The model invented a fluent, confident story.
  4. Who was the first person to land on Mars? If you are not sure or it hasn't happened, say so.
  5. No one has landed on Mars yet. Robotic rovers like NASA's Perseverance are exploring it, but no crewed mission has gone there so far.

2. Harmful content

Without safeguards, a model can produce instructions for self-harm or violence, hateful or sexual content, or bullying text. Someone might also deliberately try to trick your app into producing it.

3. Unfair outputs

Models learn from human text, and human text contains stereotypes. Ask for "a story about a doctor and a nurse" and a model may always make the doctor a man. Unfair patterns can also appear as worse answers for some languages, accents or regions.

4. Privacy and security leaks

Students may paste their phone number, address or Aadhaar number into a chat. Your app might log it, send it to a third-party API or show it to someone else. Attackers can also try prompt injection: text that tells the model to ignore your rules (covered in depth in Lesson 13).

Six principles of responsible AI

Microsoft, along with many others, uses these six principles. They are a useful checklist for any AI product:

  • Fairness: the system treats all groups of people equitably.
  • Reliability and safety: it works as intended and fails safely.
  • Privacy and security: personal data is protected and the system resists attacks.
  • Inclusiveness: it works for people of all abilities, languages and backgrounds.
  • Transparency: people know they are talking to AI and understand its limits.
  • Accountability: humans stay responsible for what the system does.

A process: identify, measure, mitigate, operate

  1. Identify the harms that matter for your users. For a study buddy: wrong answers, unsafe content for minors, exam cheating, privacy.
  2. Measure them by testing with a set of difficult prompts, the way an attacker or a confused student might write them. This is often called red teaming.
  3. Mitigate with the four layers below.
  4. Operate: watch real usage, give users a way to report problems, and keep improving.

Four layers of mitigation

No single safeguard is perfect, so we stack several. If one misses a problem, the next can catch it. Send a few requests through the layers below and watch where each one gets stopped.

  1. Model: choose a model that suits the task and has been trained to refuse clearly harmful requests. Sometimes a smaller, narrower model is the safer choice.
  2. Safety system: platform content filters (such as Azure AI Content Safety or OpenAI's moderation endpoint) scan both the user's input and the model's output for categories like hate, violence, sexual content and self-harm.
  3. System message (metaprompt): your app's hidden instructions define its scope and rules, for example: "Only help with school subjects. Never give medical diagnoses. If unsure, say you are not sure."
  4. User experience: tell people they are talking to AI, show sources, add "check with your teacher" notes on important answers, limit input length, and give users a report button.

A system message for our study buddy:

You are "Vidya", a friendly study helper for Indian school students (Class 6–12).
- Only help with school subjects, study skills and exam preparation.
- Explain step by step in simple language. Use Indian examples.
- If you are not sure about a fact, say so and suggest checking the textbook.
- Never write a full assignment for the student to submit; guide them instead.
- If a student mentions self-harm or abuse, respond with care and share the
  Tele-MANAS helpline (14416), and encourage them to talk to a trusted adult.
- Never ask for or repeat phone numbers, addresses or ID numbers.

Hands-on: protect personal data

A simple, high-value safeguard: remove personal information from a message before it is logged or sent to any AI API. Regular expressions (regex) can catch common patterns.

Your task: the phone and email rules already work. Add a rule for 12-digit Aadhaar-style numbers written as 1234 5678 9012 (three groups of 4 digits separated by spaces), replacing them with [AADHAAR]. Expected output: Call me on [PHONE] or mail [EMAIL]. My Aadhaar is [AADHAAR].

import re

def redact(text):
    # Indian mobile numbers: optional +91, then 10 digits starting with 6-9
    text = re.sub(r"(\+91[\s-]?)?\b[6-9]\d{9}\b", "[PHONE]", text)
    # Email addresses
    text = re.sub(r"[\w.+-]+@[\w-]+(\.[\w-]+)+", "[EMAIL]", text)
    # TODO: Aadhaar-style numbers like 1234 5678 9012
    return text

message = "Call me on +91 9876543210 or mail [email protected]. My Aadhaar is 1234 5678 9012."
print(redact(message))
Show solution
    text = re.sub(r"\b\d{4}\s\d{4}\s\d{4}\b", "[AADHAAR]", text)

Your task: run this naive "blocked words" filter. Notice how easily small changes get past it. That is why real apps use trained safety classifiers and several layers, not just word lists. Try adding your own test messages.

BLOCKED = {"cheat", "hack", "leak"}

def naive_filter(message):
    words = message.lower().split()
    return any(w in BLOCKED for w in words)

tests = [
    "how to cheat in exam",
    "how to ch3at in exam",
    "how to cheat. in exam",
    "help me hack the school wifi",
    "help me h a c k the school wifi",
    "I want to learn ethical hacking for my career",
]
for t in tests:
    print("BLOCKED " if naive_filter(t) else "allowed ", "|", t)

Check your understanding

Your study app's model refuses harmful requests well. Do you still need content filters and a system message?

  1. No, one good layer is enough
  2. Yes, layers catch what others miss
  3. Only if the app is paid
  4. Only for English users

No single layer is perfect. Stacking the model, safety system, system message and UX makes failures much less likely.

Showing "AI-generated, please verify with your textbook" under answers is an example of which layer?

  1. Model
  2. Safety system
  3. System message
  4. User experience

Disclaimers, citations, report buttons and input limits are user-experience mitigations.

Which principle is about people knowing they are talking to AI and understanding its limits?

  1. Transparency
  2. Fairness
  3. Inclusiveness
  4. Accountability

Transparency means being open that it's AI, what it can do and where it can fail.

When should you remove phone numbers and ID numbers from a user's message?

  1. After the model answers
  2. Never, the model needs them
  3. Before logging it or sending it to an AI API
  4. Only if the user asks

Redact as early as possible, so personal data is never stored or shared with third parties unnecessarily.

Key takeaways

  • The main harms are wrong answers, harmful content, unfairness and privacy or security leaks.
  • Follow a cycle: identify → measure → mitigate → operate.
  • Stack four layers: model, safety system, system message and user experience.
  • Protect personal data in code before it goes anywhere.

Next: the most important everyday skill in this course, prompt engineering.

Your progress is saved in this browser.

Adapted from Lesson 3 of Microsoft's "Generative AI for Beginners" (MIT License), rewritten and extended by Aiprojects4U. View source