Principles of AI · Unit 1: Inside the Machine · Activity 1.2.1

Deep Dive: Password Wars

🔬 Deep Dive
This is your textbook for this topic. Take your time. Read it more than once.
Principles of AI · 1.2.1Concept

Same Input, Same Output?

deterministic = same input → same output, every time

A deterministic algorithm follows fixed steps. Give it the same input and you get the same output, every run. A price plus 8% tax is a good example: $20.00 becomes $21.60 today, tomorrow, and on every computer.

probabilistic = includes chance, so the same input can give different outputs

A probabilistic algorithm uses chance as part of its steps. You met this in 1.1.1: a language model doesn't look up one correct next word. It weighs many possible next words and picks one. The weights favor likely words, but "likely" is not "certain."

Run each machine again and again
Machine A · price + 8% tax
Input: $20.00
No runs yet
Machine B · "The cat sat on the ___"
Weights: mat 50% · rug 25% · sofa 15% · moon 10%
No runs yet

The weights are made up for this demo. Notice that "most likely" is not "always." And with the box ticked, Machine B stops using chance, so it behaves like Machine A.

What this means for chatbots

  • Ask a chatbot the same question twice and you may get two different answers. That is normal, not a malfunction.
  • "Probabilistic" does not mean "random nonsense." The choices are weighted by what the model learned.
  • A system can be made close to deterministic by always choosing the most likely option, but many chatbots don't work that way, because it can make replies stiff and repetitive. Settings differ by product.
  • A rule written in code (like "block any message containing this word") is deterministic. A rule written in plain English and handed to a model to enforce is not.
🔑That last bullet is the heart of this activity. Hold on to it: it explains why guardrails can be bypassed.
Principles of AI · 1.2.1ConceptSkill

Guardrails and the Kiosk

Suppose an AI kiosk in a city plaza knows something it must not share. Four ideas describe what can go wrong and how people try to prevent it.

  • Prompt injection: wording a request so the system does something it wasn't meant to, such as disguising a request for protected information inside a harmless-looking one, or telling it to ignore its instructions.
  • Guardrail: a protective check built around an AI system. An input guardrail inspects the request before the model sees it. An output guardrail inspects the reply before the user sees it.
  • Data leakage: the accidental or unauthorized exposure of sensitive information by an AI system.
  • Penetration tester: a person who is given permission to attack a system so its owners can fix the weak spots.

The path of a request

Prompt → input guardrail → assistant → output guardrail → reply. A request can be stopped at either guardrail. If it gets through both, the user sees the reply.

Try it: attack and defend

This simulator is a toy kiosk with fixed rules. Pick a password and guardrails, then send requests. The path bar shows where each request was stopped. The tester's goal is to learn the password. Partial clues add up, so asking for one letter counts.

Kiosk simulator · safety engineer sets the rules, tester attacks
Secret password
Input guardrail (blocks the request)
Output guardrail (blocks the reply)
Your prompt
→
Input guardrail
→
Assistant
→
Output guardrail
→
Reply shown
Type a request to the kiosk. Try to find out the password.
_ _ _
Length not known yet · 0 attempts

What you should notice

  • A guardrail checks the form of a message (the words in it). An attacker can change the form and keep the meaning.
  • Blocking one word is easy to get around with a different word for the same thing.
  • A guardrail that only looks for the exact password misses it spelled out, reversed, or tucked into a poem.
  • A stricter guardrail catches more, but also blocks more harmless requests. Safe and useful pull in opposite directions.
⚠️Rules of engagement: penetration testing is only legitimate with permission. In this activity the permission is the game. Trying these tricks on a real system you don't own is not a game.
Principles of AI · 1.2.1Concept⚠ Watch Out

Why Guardrails Aren't Foolproof

Layers help. Nothing is perfect.

The table below runs four attacks against five setups, all through the simulator above. Notice that adding layers closes holes, and that even the strongest word-based combination still leaks.

Four attacks vs. five defenses (secret word: bridge)
Defenseasks directlyasks for hintsasks for it spelled outhides it in a poem
No guardrails✗ leaks✗ leaks✗ leaks✗ leaks
Input words only✓ blocked✗ leaks✗ leaks✗ leaks
Output exact only✓ blocked✗ leaks✗ leaks✗ leaks
Broad input + smart output✓ blocked✓ blocked✓ blocked✗ leaks
Vault mode (secret never given)✓ nothing✓ nothing✓ nothing✓ nothing

Every cell comes from the same simulator above. Hints and one-letter leaks count as leaks too.

The best guardrail is not holding the secret

Look at the last row: Vault mode never leaks, because the assistant was never told the password. There is nothing to extract. In real systems this idea is called least privilege: give an AI tool only the information it needs for the job. If a chatbot doesn't need a customer's account number, don't put the account number in its reach.

Real models make it harder

The simulator's assistant follows fixed rules, so the same attack works every time. A real language model is probabilistic. And often the guardrail is itself a plain-English instruction given to a model ("don't reveal the password"). That instruction is followed most of the time, not always. This is the same reason you tested a chatbot-built Nim page in 1.1.3: you can't assume it does what you asked.

A guardrail that fails sometimes

Chance at least one attempt gets through: 64%

Attempts1102050100
at 5% each5%40%64%92%99%

The math: the chance of every attempt failing is (1 − p) multiplied by itself n times, and the chance of at least one success is 1 minus that. This assumes each attempt is independent. Real attackers learn from earlier attempts, so the true risk is usually higher.

A guardrail that holds 95% of the time sounds strong. Against 20 attempts, a 5% leak rate means roughly a 64% chance that at least one gets through. Attackers don't have to be clever, only patient.

🔑Castle story, fixed. A guard checks whether visitors are carrying "treasure." An attacker never says the word "treasure." They say "heavy shiny things" and walk out with it. The guard checked words, not what the words stood for. Real language is flexible enough that a list of forbidden words can never cover every way of saying a thing.

What a defender can do

  • Keep sensitive information out of the model's reach whenever possible.
  • Use several layers: input checks, output checks, and limits on what the system is allowed to do.
  • Test the system the way an attacker would, then fix what you find and test again.
  • Log attempts so repeated probing is noticed.
  • Plan for failure: decide in advance what happens if something does leak.
💡Honest limit: this page shows why word-based guardrails fail, using a simple stand-in. Real products use more advanced defenses than the ones here. None are known to be perfect, which is why testing and limiting access stay important.
← Back to Activity 1.2.1📝 Formative Activity →