This website uses cookies

Read our Privacy policy and Terms of use for more information.

I had a wonderful time this weekend with my kids; we have rekindled a tradition of sitting around a table and painting for a few hours. It is something that we enjoyed when they were younger and something that we still enjoy today. This week's image is the painting that I painted. It's clearly my brightly colored style. But it also feels a bit like flying or exploring a new world.

Working with LLMs this past week has felt the same way: new territory, no clear map. To keep myself oriented, I've started documenting the patterns I use when writing code that calls an LLM. You're seeing the first pass. I'd love to hear what you think.

The Pattern of the Week segment replaces Links Worth Your Time, but those curated finds still live on the site at finds if you want to browse them.

Pattern of the week

Logic or Generation?

This pattern names the intention of each piece of code before you write it. Either the code is deterministic logic (the output is fully predictable from the input) or it hands control to an LLM, where the output varies. The distinction matters because mixing them without labeling them produces bugs that look like logic errors but are actually unpredictable LLM output. Before you write a line, ask: does this function own the logic, or does the model?

import ollama

def score_article(title: str, summary: str) -> int:
    response = ollama.chat(
        model="phi4-mini",
        messages=[{
            "role": "user",
            "content": (
                f"Rate 1-10 for a Python/AI developer.\n"
                f"Title: {title}\nSummary: {summary}\nNumber only."
            )
        }]
    )
    return int(response['message']['content'].strip())

# This code owns the logic
articles = fetch_feeds(sources)    

# LLM owns the generation      
ranked = sorted(
    articles,
    key=lambda a: score_article(a['title'], a['summary']),
    reverse=True
)                                         

This week on the blog

This week I published Your Local AI Stack: uv and Ollama in 10 Minutes. The part worth knowing: uv lets you declare dependencies in a comment block at the top of any Python file, and uv run installs them automatically. No virtualenv, no project setup. One file, one command, local LLM running. The patterns I write about in this newsletter use this exact setup. Worth getting it running now so you can follow along.

What I'm learning

LLM prompts are not function signatures. I keep writing them as if precision guarantees the output I expect, the way a well-typed Python function would. It doesn't work that way. The model interprets, doesn't execute, and the gap between those two things is where most of my surprises have come from this week.

Closing Question

What's the first task in your own code you'd hand to an LLM instead of writing the logic yourself? Hit reply and tell me.

-Jamal

Find me on LinkedIn · Bluesky · X · Mastodon

Not subscribed yet? Fix that here: jamalhansen.beehiiv.com

Keep Reading