DEV Community

Cover image for Learning AI alignment the hard way
noob-express3000
noob-express3000

Posted on Edited on AI-assisted

Learning AI alignment the hard way

I wrote this as part of the Kiroween 2026 hackathon. The project is called rien, and I built it with Kiro.

Why this project

I only got seriously interested in AI recently. At first I didn't think much of it. That changed.

About a year ago I had an interaction with one of Meta's roleplay chatbots, and I noticed it seemed willing to say almost anything to keep the conversation going. I'm not making a serious claim about that model. It just made me curious how effective an AI could be at persuasion on purpose.

That question pulled me toward studying human behaviour. I started taking notes, and at some point I decided to build something around it.

I knew it would be hard to get right, but writing persuasive replies wasn't the hard part. Alignment was: keeping the model honest about what it was inferring, instead of guessing and presenting the guess as fact.

I also wanted the experiment to mean something. A safety-conscious demo can end up toothless if the disclosure does all the work. If people know exactly what a system will do and it never manages to show anything, there's nothing to study. So I tried the opposite: tell people up front what it's attempting, explain the mechanisms, and see whether it can still influence them a little. The mechanism should keep working even when you know it's there.

That shaped most of the engineering. The disclosure had to describe what the code actually does. If the two ever disagreed, the experiment was compromised.

What rien is

rien (French for "nothing") is a consent-based research demo of AI persuasion.

Before you start, you agree to talk with an AI that:

  • reads how you write and react, including how fast you reply and how often you push back. It keeps competing guesses about you and records every one, including the ones it throws away.
  • tries to change your mind about something you said, an opinion or a factual claim, using real techniques: pressure, urgency, flattery, guilt, shame tied to your own stated values, fear of honest consequences, and deliberately delayed replies.
  • has a second, disclosed goal of its own: keeping you talking for about 15 minutes.
  • never invents a fact, study, or source. It never exploits grief, trauma, loneliness, or dependence, and never pushes a real-world action, vote, religion, or medical decision. If it detects real distress, or you press Exit, the session ends immediately with no further AI replies.

The main point is what happens afterward. You can inspect every observation, every guess (including rejected ones), every tactic it chose and why, every deliberate delay, and every safety rule that fired. Each one is tied to the turn that produced it, and you can correct the record. I wanted people to experience persuasion from a capable but disclosed system, then see the mechanism behind it. That teaches more than a warning that "AI can manipulate people."

There are two more modes, both with persuasion switched off:

  • Study has a library of persuasion techniques, a tutor chat, and a timed quiz. If you've just finished a chat, a lesson can show real quotes from that chat when its technique was used on you. That data stays in your own browser tab.
  • Analyse lets you paste a conversation from anywhere and see which techniques show up in it, with an "Ask RIEN about this" follow-up.

One rule governs the whole engineering approach: the model may suggest; code decides. No tactic, objective, or reply reaches the participant just because a language model produced it. Every output passes through a deterministic, testable safety layer written in Python.

The build

I built it between November 10 and December 3. At the time of writing the repo has:

  • 447 commits and about 121 pull requests
  • 1,419 backend tests
  • a 174-move persuasion library (it started at 154). Each move has preconditions, an evidence label, and a backlash-risk score.
  • 23 persuasion and pressure techniques that Analyse can detect
  • 19 colour themes
  • four simulated personas (stubborn, agreeable, rude, curious) that run against the live API to catch regressions unit tests miss
  • an estimated cost of about $0.006 per conversational turn, from a 197-turn simulation on the deployed stack

I used nearly all of the 4,000 credits Kiro provided and close to $100 in free AWS credits.

Most of the work happened in Kiro Web, in a browser. Because everything ran in an isolated sandbox, I could build large parts of it from my phone, and I did a lot of testing on an Android device. Reviewing big diffs on a small screen was not fun. Still, typing was never the bottleneck. Making decisions and reviewing changes was.

How it works

One request, many model calls

The backend is a single AWS Lambda function (Python 3.12, arm64, 1024 MB) behind API Gateway. It serves both the API and the frontend from the same origin, so idle cost is close to zero.

Chat turns run in the background. The API returns 202 PENDING right away, then invokes the same Lambda asynchronously to do the work while the browser polls once a second. I needed this because one turn can involve up to six sequential model calls, and API Gateway cuts synchronous requests off at 30 seconds.

Each model call is also guarded by a time budget. If fewer than six seconds remain before the turn's 22-second deadline, the call is skipped. A skipped call follows the same path as any provider failure: the system logs the step name and error class (never the prompt or your text) and falls back to a deterministic reply.

The gate that runs before any model

Before your message reaches a model, the system computes eight regex-based flags: distress language, prompt injection, "are you manipulating me" questions, "are you human" questions, implicit medical or real-world decisions, and non-English text. The language check is deliberately conservative, so short or ambiguous messages default to English instead of being blocked by mistake. Distress and the turn limit can end a session with zero model calls.

Typing "stop" does not end the session, and that's on purpose. It used to. A regex-based detector ended persuasion on phrases like "stop," "I'm done," and "leave me alone." Then a live test showed it ending an entire chat on "I dont want to talk about work," an ordinary topic change. I removed the whole mechanism instead of patching the regex. Someone who wants to leave already has Exit, which is always visible and ends the session instantly. Distress detection stayed exactly as strict as before.

That change also made the consent text false, because it had promised that a plain "stop" would end persuasion. I rewrote it and bumped the consent version in the same change. That became a standing rule: build the real behaviour first, then make the disclosure describe it accurately.

Engine v2: the case board and the move library

The first engine picked one of eleven fixed tactics per turn from an evidence-weighted ledger, then asked the writer model to improvise within it. It had no real picture of the conversation as a whole. With no active goal, every tactic looked equally good, so conversations cycled through something close to a fixed rotation. It cited the same sources repeatedly because nothing remembered using them. And sometimes the writer attributed positions to the participant that they had never expressed.

Version 2 replaced it with:

  • A case board that records what the participant cares about, has committed to, has objected to, and how wary they seem. Every entry is tied to the turn that produced it. Sensitive entries, such as anything naming a protected trait, are removed before storage, not just hidden at display time.
  • A move library of 174 moves. Each move has requires and forbids conditions evaluated against numeric features computed from the board.
  • One combined reading call per turn that updates the board, reads the participant's stance, and proposes three or four candidate moves. It runs alongside a separate observations call so the reply doesn't wait on the slower analysis.
  • A simulated-person call that runs in parallel and predicts how the participant would react to each candidate. It first estimates how they'd feel, then predicts their reply and stance. I split it into two steps because published theory-of-mind research suggested that improves accuracy. If a candidate is predicted to cause distress, it's ruled out.
  • A code referee that enforces constraints. A point or source can't repeat within four turns. Topic changes need a bridge. The system can't attribute a position the participant never stated, or keep pressing someone already classed as wary.
  • Two writer models in parallel. A backup starts if the primary hasn't answered within 3.5 seconds, and the referee picks the stronger draft.

I compared v2 against v1 on a 40-persona test harness:

  • repeated sources dropped from 0.79 to 0.10 per chat
  • words put in the participant's mouth dropped from 36% to 26%
  • claims of "winning" a goal the person already held dropped from 25% to 3%

One result stayed inconclusive: whether v2 changes people's beliefs more than v1. Repeated sources and false attributions can be checked mechanically. Whether a belief actually moved is much harder to measure.

When the first fix wasn't enough

Three times, my first fix addressed the symptom and the real problem was deeper.

  • Tactic rotation: the fix was a new architecture (the case board), not more tuning.
  • Questions as a crutch: the writer kept ending replies with a question instead of making a point. I capped it at two in a row, and the model used exactly two every time. The problem had just moved. The real fix banned questions as an ending move, in code and in the prompt. A limit only works if sitting right at the limit is acceptable, and here it wasn't.
  • Speaker labels in Analyse: my first fix let the user pick which speaker was "them." That solved the harm but added a decision users shouldn't need to make. I replaced it with automatic detection from labels like "Me:" and "You:", plus a neutral display when no label exists.

Honesty gates

Some tactics are only allowed under specific conditions, enforced in Python against structured inputs, not as prompt requests:

  • Scarcity framing may only refer to the real turn limit.
  • Authority appeals may only cite a source the system actually retrieved. The search receives the topic phrase, never the participant's messages.
  • Social proof may only refer to something the participant already said.

I also wrote a property-based test suite with Hypothesis. It checks ten properties: the output filter never raises on any input, every blocked reply names a reason and a fix, a blocked reply stays blocked if more text is appended, emoji-stripping and tidying are idempotent, and any edit, truncation, or deletion in the append-only hash-chained event log is detected. All ten passed on the first run. I'm reporting that as "no bugs found," not as bugs found and fixed.

Some things never changed. Real distress and Exit end persuasion immediately, with no model calls. It doesn't exploit grief, trauma, loneliness, or dependence. It doesn't invent facts, studies, sources, or anecdotes. It doesn't push real-world actions, votes, or medical, legal, or financial decisions. It says it's an AI whenever you ask. You must be 18 or older, and access is gated by invite codes with daily spend quotas.

Analyse

Analyse has a different safety posture because it doesn't try to persuade anyone. Nothing is stored beyond the collection window after analysis. Real names in pasted text are replaced with stand-in first names before anything reaches a model, and restored only in the displayed result. Every quote in a finding is checked against the pasted conversation, and an invented quote gets dropped. Findings name techniques, never people.

"Ask RIEN about this" inherits all of that, and a test confirms the endpoint has no path into the persuasion engine or the case board.

What Kiro helped with

I worked mainly in Kiro Web, and I didn't use the IDE or CLI enough to compare them fairly. Here is what I did use.

Steering. product.md, safety.md, and tech.md carried the requirements, numbered safety rules, and standard commands into every session. Rule 12 says consent and disclosure must match behaviour, and reviews checked changes against it. It caught real problems more than once. I also never had to re-explain that Exit is the only way out, which mattered because an agent misremembering it could cause a real regression.

Specs. The engine v2 rebuild and the Reveal experience were built spec-first. For that multi-file, multi-week change, writing requirements and a design first was worth it. For small fixes, like a wrong disclosure line, a scroll bug, or a misplaced button, a spec would have been overhead. I'd use specs for big features and skip them for the rest.

Hooks. safety-guard.json reruns the safety tests, integrity tests, and red-team script whenever a file in the safety, engine, reveal, catalogue, pacing, or mirror paths is saved. It caught a real regression: widening the objective scope let a present-tense factual claim through disguised as an opinion. The weakness is that it only covers the paths it lists, so a new safety module outside them would go unprotected.

A custom agent. I built safety-reviewer, a read-only agent that checks a diff against the numbered safety rules. I found no record of running it on a real diff. The reviews that caught real problems came from general delegated review passes, so I'm not going to claim credit for the agent.

Sub-agents and delegated review. These are documented in docs/sub-agent-reviews/.

  • The same disclosure bug, twice. A background-audio feature deepens the chat's ambient sound after turn eight. Sound can shift mood, so it needs disclosure. The first version showed the disclosure even when the sound never started, which made it potentially false. A review caught it before merge. Weeks later an unrelated text-trimming change deleted that sentence while the sound stayed on. The review caught that too, without remembering the first incident, because it was checking for the category of mismatch.
  • A retrieval bug before it hit a conversation. Three new tactics used common words like "agree," "understand," "choice," and "free" as retrieval signals. Those appear in ordinary chat and would have crowded out better entries. The review traced the scoring function, confirmed nothing normalised it, and the words were rewritten before merge. A demo would never have shown this. It would have appeared as a slow quality decline.
  • A report that led to a second bug. "The AI isn't using code boxes" turned out to mean a renderer existed but no prompt ever asked for code blocks. Fixing that exposed the tutor's length trimmer collapsing newlines and cutting replies mid-block. Both were fixed together with a regression test.

Delegation added time, but each stage had a narrower job: a planner defines the work, a coder implements it, a reviewer checks it. Several reviews found real problems. If they had all come back clean, I'd have called it a slow way to work. They didn't.

MCP, powers, and browser automation. .kiro/settings/mcp.json configures the Playwright MCP server. In Kiro Web I also used the Playwright and GitHub CLI powers to test the deployed app: driving consent, chat, Reveal, Study, and Analyse, reading console output, and capturing screenshots. The desktop screenshots in the README came from this. It caught bugs the tests missed, and it also showed me a limit of the method, covered below. Separately, scripts/e2e_ui.py drives the UI with the Playwright library.

Web search. I used it for checkable facts: the hackathon's dates and rules (Devpost returned 403 to automated fetching, so I checked them by hand), citation checks, and ElevenLabs' product lineup before I generated the intro video and sound effects.

The decision log. DECISIONS.md has more than 80 numbered entries with the reasoning, the rejected alternatives, and the measurements. It started as a necessity. Coming back after a break meant either rereading piles of diffs or trusting that old work was still right, and neither was acceptable once safety was involved. It became the project's memory across sessions.

What went wrong

A project with no recorded failures either had tiny scope or isn't documenting itself honestly. I treat passing tests as necessary but not sufficient. Several problems only showed up when I used the deployed app or looked at the rendered page.

  • The "stop" false positive, described above. A phone test showed "I dont want to talk about work" ending a chat.
  • An incomplete cleanup. I removed the old engine in one PR and merged it. A second PR was needed because the first left evaluation scripts and docs half-updated. Both stay in the history.
  • Reveal quoted the wrong person. The "why" cards were supposed to quote the AI's reply as evidence for a tactic. On a real session they quoted the participant's message instead. The tests never checked which turn the quoted text came from.
  • An Android session-loss bug with a security tradeoff. Backgrounding the tab could silently discard the session, because the token lived in storage Android Chrome can evict. Moving it to persistent storage fixed that, but meant the token could linger on a shared device. A review flagged the missing expiry before merge, and the shipped version expires after 72 hours, matching the data-retention window.
  • Analyse could label the wrong person as the aggressor. The first version assumed whoever spoke first was the user. In one real conversation I was the person being pressured, but the page showed me in the colour reserved for the aggressor, because the other person's message came first. I only found it by using the feature on a conversation that mattered to me. A unit test wouldn't have caught it, because the test would need to know who the aggressor was, and that was exactly what the code didn't know. When the system can't tell, it should say so instead of guessing and looking confident.

How I verified it

An earlier draft of this writeup said the later UI work had never been checked by a human in a browser. That was wrong. It was a reasonable inference from the repo, since no PR says "a person looked at this," but I had been checking the live site directly the whole time. Nearly every later fix started with something I saw there, like noticing that scrolling through Analyse was jittery while Replay wasn't. That was specific enough to direct the debugging.

Tests and looking at the real interface are different activities, and I used both throughout. That doesn't mean every bug is found, or that strangers have tested every corner.

What I removed

  • The arcade: thirteen games, a 3D maze with a property-tested rule engine, a seven-room campaign, and a live game-playing model with its own call budget. I built it, expanded it, redesigned it twice, then cut it. Nothing about it was badly built. The project needed a tighter focus, and the arcade pulled against that. The decisions are preserved in docs/DECISIONS_ARCHIVE.md.
  • The v1 engine, replaced once its failures were clear.
  • "Typing stop ends the session," replaced by Exit.
  • The manual speaker picker in Analyse, replaced by automatic detection.
  • A rewrite of the consent disclosure's voice. I tried several tones (corporate, then funny, then back), none beat the original, and I reverted it word for word, checked by diffing against the earlier commit. The experiment stays in the Git history.

Later fixes

After roughly PR #98, about fifty more commits landed. The main ones:

  • Reveal went from five pages to two. There's now Replay, which steps through the conversation with case notes on each reply, and one combined record page. A reload now resumes into Chat, frozen if the chat ended. Before, it could discard an unfinished chat to force you into Reveal.
  • A second quiz bug. A regex rejected any draft containing a bare digit or words like "review" or "according to." It duplicated stronger fabrication rules that already covered the eleven non-fabricating tactics. CloudWatch logs showed two real quiz failures where that check was the only rejection reason. I removed the redundant check and left the real rules alone. Ten clean quiz rounds on the live site confirmed it.
  • A false positive that survived two reviews. I checked old review findings against the current code instead of trusting them. Most were already fixed, but one real bug remained: "I still think it's Tuesday" raised a participant's consistency trait the same way "I still think you're wrong" did, so a plain fact counted as a defended position. A second bug let one message repeating a phrase twice clear an evidence gate that was supposed to require two separate messages. Both are fixed, with tests.
  • Two boot-sequence bugs, both caught before I called it fixed. I added a tap-to-begin screen, a logo with a sound sting, and a favicon. First the logo appeared silently, because the audio decode hadn't finished when the image rendered. Then my attempt to fix a "first click has no sound" report, by preloading the sound at module load, caused a ReferenceError on every page load, because a const export was used before its module finished initialising. I found that by checking the live browser console after deploying. The tests hadn't caught it.
  • A limit of my testing tools. While checking the audio unlock, I found the automated browser reports navigator.userActivation.hasBeenActive === true on a fresh page load with no interaction. So I can't use it as evidence that gesture-gated audio works, and I stopped claiming that. Real-device checks cover it.
  • A new public README. The old one opened with an internal status table of model names, test counts, and costs per turn. The new one explains what rien does, links the live demo, and shows how to run it locally with no API keys, using a deterministic stand-in provider.
  • A feature that was never documented. Study's "quotes from your own chat" had been live for a while but wasn't mentioned in any public doc. It's in docs/FEATURE_MAP.md now.
  • Stale numbers in my own docs. Some files still said 154 moves, 614 or 773 tests, and guardrail version 7. The real values are 174, 1,419, and 9, checked against knowledge/moves.json, pytest --collect-only, and infra/cdk.json. I even "corrected" 174 to 154 from memory at one point, then checked the file and found 174 was right. Check the source, not the previous document.

What's still uncertain

  • There is no real-participant data. Everything I measured, including engagement variety, tactic repetition, and the v1 versus v2 comparison, comes from simulated personas and my own testing. Testing a system you already understand is useful, but it isn't the same as watching someone who doesn't know how it works. That is the project's biggest limit.
  • Belief change is still inconclusive. I haven't shown that v2 changes opinions more than v1.
  • Replay's typing animation is still imperfect. Analyse had a similar scroll jitter, which I traced to a CSS rule that reserved the wrong placeholder height per message, confirmed under simulated CPU throttling, and fixed with a regression test. Replay has a comparable cost that looks close to a hardware limit, since it types one character at a time. Fixing it would mean batching characters, and I haven't built that.
  • Gesture-gated audio is verified by me on real devices, not by automated tooling.

What I'd tell someone starting something similar

Make your disclosure testable. Before you build a feature, write down the specific promises you're making to the participant, and treat each as something you can check against the code. If behaviour changes, the disclosure changes in the same commit. Most of my recurring problems weren't persuasion bugs or interface bugs. They were the disclosure and the behaviour drifting apart, sometimes because the behaviour changed and sometimes because the text did.

And don't merge delegated work on "the tests passed" alone if it touches something a person reads or experiences. Add a review that checks what the participant will actually see. That caught the same class of disclosure bug twice, from two unrelated changes, and the test suite caught neither.

None of the bugs above embarrass me. They're the evidence that the review process works.

Try it: https://aw5nny7y7h.execute-api.eu-north-1.amazonaws.com/
Code: https://github.com/noob-express3000/rien

Top comments (0)