Skip to content

Latest commit

 

History

History
91 lines (63 loc) · 2.55 KB

reflection.md

File metadata and controls

91 lines (63 loc) · 2.55 KB

Review your own draft

The problem

A bakery writes a job ad. It must follow ten house rules, such as a word count and a fixed last line.

The first try asks once, with all ten rules in the prompt. The ad reads well. It still breaks some rules.

How it works

Review each draft against the house rules.

This is reflection. The model checks its own draft, then writes it again.

  1. The model writes a first draft.
  2. A second request only judges. It quotes the words, then says pass or fail for each rule.
  3. Code lists every rule that failed or was skipped. This list is the gate.
  4. The model rewrites the draft. This can happen two times.
  5. Every rewrite is judged, the last one too. The draft with the fewest failed rules wins.

For example, a review may find an exclamation mark. The rewrite takes it out.

The flow

sequenceDiagram
    participant Shop as Your code
    participant Model
    Shop->>Model: write the ad
    Model-->>Shop: draft
    Shop->>Model: check each rule
    Model-->>Shop: pass or fail
    alt a rule failed or was skipped
        Shop->>Model: rewrite and fix it
        Model-->>Shop: new draft
    else all rules passed
        Shop->>Shop: keep the draft
    end
Loading

Concepts

  • Reflection is the loop of draft, review and rewrite.
  • The list of failed rules works as a gate.

Run it

uv run lab reflection naive
uv run lab reflection

Add --case 2 or --case 3 to try the other cases.

Prove it

There are three jobs with ten rules each. Code checks the final ad, out of 30.

Version Rules followed
Ask once 23
Draft and review 29

Now break it. Open the pattern file and find to_fix. Make it return an empty list. Then run the test:

uv run pytest tests/promises/test_reflection.py

The test fails, because a draft with broken rules is now kept.

Stuck points

  • A "no key found" message means the key file is missing. Copy the example file and paste your key.
  • If a rule still fails at the end, the two rounds ran out. The last review shows which one.

What to watch for

The review is the model judging itself. It can miss things or complain about good text. When code can check a rule, let code check it.

It costs more calls than asking once.

Where to go next

Go to Call tools. It lets the model look things up.