Charts in the era of Prompting
Hey Again!
Welcome to this second installment of things that sounded trivial to start with but are interesting if you think long enough about them, a.k.a. my posts. I know these things take longer than expected but I’m really happy I’ve found the time to keep writing. Also, please forgive the amateur writing style that you see, this is me improving by doing.
The second post in this series is about graphs, not the data structures, but actual graphs that you would use to describe the design of your system. Graphs that allow you to understand what is going to happen before the code is even written. The idea came from watching Why Software Factories Fail, a talk by the folks at HumanLayer, who I’ve been learning a lot from lately.
Ask and you’ll receive
I’m pretty sure that at some point you gave a task to your coding assistant and it did what you wanted, then reported back like:
<A small summary of what it did>
What was wrong: <a short description of the problem>
What I changed:
- <first change, usually not the most important one>
- <second change, this one might include an example in the middle>
- <n-change>
Worth knowing:
- <examples about what you should ask next>
And that might work super well for tasks that are not that complex, like rewriting an email. Once complexity grows though, the bullet points become insufficient to paint an accurate mental picture of what changed, at least not without taking a big chunk of your time to draw the picture yourself. But, why a picture? Why not just better text?
Why was I here?
Have you ever gone from one room to another just to find out that you no longer remember why you wanted to go to that room in the first place? That’s called the doorway effect and it’s triggered by our brain dumping the context1 Get it? Your context, like an AI assistant session? that it had about the current task because it perceives the switch of rooms as the boundary of that activity. Other things can trigger that “event boundary”, like when someone interrupts your train of thought or when you try to multitask.
Conversely, if you manage not to cross any event boundary, you are more likely to finish the task at hand, in our case, to go through the full list of changes without losing yourself in the middle.
On top of that, the points by themselves are good, but they have to work extra time to portray how they are related to each other. Imagine 3 friends that want to visit each other’s houses without their phones. The obvious solution to that problem would be a map, which represents where each house is relative to the others. A bullet list with the instructions on how to get from one to the other could be useful, but if you want to picture in your head what that would look like, you’d better draw out those instructions and build a map.
Navigating ideas can be as easy as navigating a map. In fact, the hippocampus, the part of our brain that builds maps of the places we visit, seems to map ideas in a similar way. The connections between them don’t need to be illustrated by a long list of directions to take. Instead, you simply draw those directions on a map and use it to go from point A to B.
The list of instructions is like those bullet points LLMs produce: they can be precise, but they leave you feeling lost in the middle because you crossed an event boundary and they don’t provide an easy way of expressing the relationships between them.
The maps
So, if you want to really understand how those bullet points are connected, then a map, or in this case, a graph is one of your best tools. I have to admit that these charts were taught to me at some point but I didn’t catch the real need for them. It’s another one of those things that you learn at uni, just to forget, just to discover again and be amazed by it.
So here are some of the maps I’ve used lately to help me understand what comes out of my assistant:
1. The state machine diagram
You need a starting point? Start with this one. Describe in brief terms the states in which your program is going to be, and the possible transitions between those states.
stateDiagram-v2
[*] --> Pending: link requested
Pending --> Used: link clicked in time
Pending --> Expired: 15 minutes pass
Pending --> Revoked: newer link requested
Used --> [*]
Expired --> [*]
Revoked --> [*]
2. The Sequence diagram
You will need more detail than that though, as who moves the process along is also important, so use this bigger brother version to represent that. The vertical axis is time so if you go down you travel to the future, bro. alt blocks show alternative paths like the previous transitions that you described in the state machine diagram.
sequenceDiagram
actor U as User
participant W as Web app
participant A as Auth API
participant D as Database
participant M as Email provider
U->>W: Submit email
W->>A: POST /auth/link {email}
A->>D: Save token (hashed, expires in 15 min)
A->>M: Send link with token
A-->>W: 202 Accepted
W-->>U: "Check your inbox"
U->>W: Click link (?token=...)
W->>A: GET /auth/verify?token=...
A->>D: Find token, check expiry, mark used
alt token valid
A->>D: Create session
A-->>W: Set session cookie
W-->>U: Redirect to dashboard
else expired or already used
A-->>W: 401
W-->>U: "Link expired, request a new one"
end
3. Entity-relationship diagram (ERD)
You will have at some point to store or manage data. This chart allows you to represent the shape of that data and the relationships between them. In the past you had to know the nomenclature for these charts, like which one is 1 to 1 or which one is 1 to many. Thankfully right now you can just ask the LLM to produce it and check the final result so, thanks AI.
erDiagram
USER ||--o{ LOGIN_TOKEN : requests
USER ||--o{ SESSION : has
USER {
uuid id PK
string email UK
timestamp created_at
}
LOGIN_TOKEN {
uuid id PK
uuid user_id FK
string token_hash
string status "pending | used | expired | revoked"
timestamp expires_at
}
SESSION {
uuid id PK
uuid user_id FK
timestamp expires_at
}
4. Program design diagram (class diagram + file tree)
So you know how LLMs normally choose implementations for you and end up choosing the “right” one? Well these charts basically determine how to construct your code. I would use these ones at the end of the planning, to understand and specify what my APIs will look like, whether they break any previous contracts or not, and how that is going to be organized in modules. Again, do not worry about being an expert at this chart. It’s more about having that visual representation that you can see and correct in case you need it. If you don’t understand something just ask your assistant, he is a pro at building these ones up.
src/
├── pages/
│ ├── login.astro # form → POST /api/auth/link
│ └── api/auth/
│ ├── link.ts # calls requestLoginLink()
│ └── verify.ts # calls verifyLoginLink()
└── lib/auth/
├── login-link.ts # the two use cases below
├── token-store.ts # DB access for LOGIN_TOKEN
└── mailer.ts # wraps the email provider
classDiagram
class LoginLink {
+requestLoginLink(email) Promise~void~
+verifyLoginLink(token) Promise~Session~
}
class TokenStore {
+create(userId, tokenHash, expiresAt) Promise~LoginToken~
+findPending(tokenHash) Promise~LoginToken~
+markUsed(id) Promise~void~
+revokeAllFor(userId) Promise~void~
}
class Mailer {
+sendLoginLink(email, url) Promise~void~
}
class SessionStore {
+create(userId) Promise~Session~
}
LoginLink --> TokenStore : uses
LoginLink --> Mailer : uses
LoginLink --> SessionStore : uses
Conclusion
For now, I think it’s enough, we have introduced our characters of the story, we will explore how to use them in practice later in other posts.
If I want you to take something out from this one though, is that charts are cool. Use them as much as you can so you can understand the programs that you create using LLMs. Creating a plan with charts is going to save you loads of time in the future, just because you won’t have to create a new mental map of your code every time you read it again.
Thanks again for reading, hope this is useful for you. I know that it is for me. Cheers!