<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Geoff Cox</title>
    <description>The latest articles on DEV Community by Geoff Cox (@redgeoff).</description>
    <link>https://dev.to/redgeoff</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F515018%2Fae597e83-8c23-4cc8-87f7-238091024e34.jpeg</url>
      <title>DEV Community: Geoff Cox</title>
      <link>https://dev.to/redgeoff</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/redgeoff"/>
    <language>en</language>
    <item>
      <title>How to set up an AI bot that reads the school email for you</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Tue, 17 Nov 2026 16:15:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/how-to-set-up-an-ai-bot-that-reads-the-school-email-for-you-555f</link>
      <guid>https://dev.to/redgeoff/how-to-set-up-an-ai-bot-that-reads-the-school-email-for-you-555f</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F10wnu1z5qybl3vxfewov.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F10wnu1z5qybl3vxfewov.jpg" alt="Headline: Your first AI agent that runs on its own every day. 1 hour to set up, 1 week of checking. Example: the school email. Beside it, a setup checklist with six ticked steps: its own email account, read-only access, the prompt, the never-rules, a week by hand, a daily schedule" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: author, drawn with code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is a step-by-step guide to setting up your first AI agent that runs on its own every day. The example is the bot that reads our kids’ school email, which I wrote about in &lt;a href="https://redgeoff.com/posts/school-email-bot/" rel="noopener noreferrer"&gt;my post on the school email bot&lt;/a&gt;. It reads the school mail and messages, and every afternoon it sends my wife Mimi and me one short email with what we need to do. You don’t need to write any code. If you can paste a long block of text and click through some account settings, you can do this.&lt;/p&gt;

&lt;p&gt;The same steps work for any inbox you can’t keep up with, e.g. a sports league, a homeowners’ association or a volunteer group. School email is just the example I know best.&lt;/p&gt;

&lt;p&gt;Setting up our bot took about an hour. Getting it to where it was mostly right took about a week of checking its work. Then, over the next several weeks, reading the digests turned up edge cases that only show up over time, and each one became a new rule. That’s a realistic budget, and the week of checking matters most, because that’s where the bot becomes something you can trust.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm0mi8sngzu486jzp898y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm0mi8sngzu486jzp898y.png" alt="Three phases from left to right: about an hour for steps 1 to 4, the accounts, read-only access, the prompt and the rules; about a week for step 5, running it by hand and checking every digest; then several weeks for step 6, on a schedule, where each new edge case becomes a rule" width="799" height="293"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Where the time goes. Not to scale.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  The Short Version
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Make a new Gmail account for the bot, and a Google Group with you and your partner on it.&lt;/li&gt;
&lt;li&gt;Create a bot in an AI agent service. Connect your Gmail and calendar read-only, and the bot’s Gmail for sending.&lt;/li&gt;
&lt;li&gt;Paste the daily prompt from&lt;a href="https://github.com/redgeoff/memex-template/tree/main/examples/school-digest" rel="noopener noreferrer"&gt;the template&lt;/a&gt;and fill in the blanks.&lt;/li&gt;
&lt;li&gt;Run it by hand once a day for a week. Check each digest against the original emails, and add a rule for every mistake.&lt;/li&gt;
&lt;li&gt;Ask the bot to put it on a schedule: every day at about 4 PM, plus a look-ahead on Saturday evenings.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The rest of this post explains why each step matters.&lt;/p&gt;
&lt;h3&gt;
  
  
  What Will You End Up With?
&lt;/h3&gt;

&lt;p&gt;Every afternoon, the bot reads the new school email and any school app you use, follows the links to the full newsletters, and writes one digest. The must-dos come first, every event has a time (or says “time not listed”), and anything that isn’t already on your calendar gets an “Add to calendar” link that takes one click. On Saturday evenings, a second email looks ahead at the next two to three weeks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjzxuel3vu51cnscq5cas.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjzxuel3vu51cnscq5cas.png" alt="An illustrative digest dated Tuesday, October 20, with made-up schools. A Top 3 must-dos box at the top: return the field trip form, book a parent-teacher conference, register for no-school-day care. Then a section per school and the after-school club, each item with a date and time or time not listed, tagged Add to calendar or Already in calendar, and a book fair with two different start dates tagged Conflict" width="800" height="760"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;An illustrative digest with made-up schools and items, to show the format.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In our house, that replaced 30-plus school emails a week and a separate school app. That being said, it doesn’t make the information go away. Mimi is often overwhelmed by how much the schools send, and she reads the digests when she has the headspace for it. Even the digests can feel like a lot. So, keep your digest short, and put the few things that really need doing at the very top. The template asks for the three most important must-dos in a short list before anything else.&lt;/p&gt;
&lt;h3&gt;
  
  
  What Do You Need?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;An AI agent service that can run on a schedule, read your email and calendar, and use a web browser. I use &lt;a href="https://cursor.com/docs/grok-bot/get-started" rel="noopener noreferrer"&gt;Grok Bot&lt;/a&gt;, which comes with my $20 a month Cursor Pro subscription, and that plan includes a generous allowance for Grok Bot right now. Pro is no longer on&lt;a href="https://cursor.com/pricing" rel="noopener noreferrer"&gt;Cursor’s pricing page&lt;/a&gt;, though, and for new subscribers the cheapest plan that includes Grok Bot is Premium, at $30 a month. Meta’s&lt;a href="https://www.meta.com/help/subscriptions/1021145227643680/" rel="noopener noreferrer"&gt;Muse&lt;/a&gt; has paid plans at $20 and $100 a month, but it’s still in limited testing and isn’t available everywhere. OpenAI’s&lt;a href="https://help.openai.com/en/articles/20001530-getting-started-with-your-dot" rel="noopener noreferrer"&gt;dots&lt;/a&gt;come with ChatGPT Pro, which starts at $100 a month. These are the prices as of November 17, 2026. They change often, so check them before you sign up.&lt;/li&gt;
&lt;li&gt;A new email account, just for the bot. It’s the only account the bot is allowed to send from.&lt;/li&gt;
&lt;li&gt;A shared mailing list, e.g. a Google Group, with you and your partner on it. The bot sends only to that list.&lt;/li&gt;
&lt;li&gt;Your calendars, shared with each other, so that whatever one of you adds, the other can see.&lt;/li&gt;
&lt;li&gt;The prompt, i.e. the written instructions the bot follows on every run. I’ve put a template you can copy in my&lt;a href="https://github.com/redgeoff/memex-template/tree/main/examples/school-digest" rel="noopener noreferrer"&gt;memex-template repo&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Step 1: Why Does the Bot Need Its Own Email Account?
&lt;/h3&gt;

&lt;p&gt;The bot needs to read your email, and it needs to send the digest. If it sent from your account, one bad run could email a teacher in your name. So, give it its own account, and only let it send from that one. Create a new Gmail account, e.g. with your family name and “school-bot” in it, and turn on 2-step verification.&lt;/p&gt;

&lt;p&gt;Then create the shared list. In Google Groups, create a group and add yourself and your partner. It works as one shared email address that forwards every email to both of you. Ours lets anyone post to it, which is the simplest setting, since the bot’s new address can send to it without any extra steps. Send a test email from the bot’s account and check that both of you get it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: How Do You Connect It to Your Email and Calendar?
&lt;/h3&gt;

&lt;p&gt;Create a new bot in your service, and connect three things to it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your Gmail, for reading. The bot reads school mail here and never sends from it.&lt;/li&gt;
&lt;li&gt;The bot’s Gmail, for sending.&lt;/li&gt;
&lt;li&gt;Your Google Calendar, for reading.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you connect your own Gmail and calendar, choose read-only access if your service offers it. A rule in the prompt is good, but a permission the bot doesn’t have is better, because it can’t be talked out of it. You can check what you granted in your Google account, under &lt;a href="https://myaccount.google.com/connections" rel="noopener noreferrer"&gt;Third-party apps and services&lt;/a&gt;. For our bot, it lists “View your email messages and settings” and “See and download any calendar you can access”, which are both read-only.&lt;/p&gt;

&lt;p&gt;Check there rather than asking the bot. While writing this post, I asked ours what it was allowed to do, and it said its connections offered tools to send email and change calendar events. The tools show up, but Google would refuse them, since the permissions behind them are read-only. In other words, the bot doesn’t know its own permissions, and the only place to find out is the permission page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl7y4qlqietr6ddaymsdq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl7y4qlqietr6ddaymsdq.png" alt="A table of five actions. Reading your email, reading your calendars and sending from its own Gmail: the tool shows up and Google allows it. Sending from your Gmail and changing a calendar event: the tool shows up, but Google refuses. Below, the two permissions our Google account lists: View your email messages and settings, and See and download any calendar you can access" width="800" height="418"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The bot sees tools it can’t use. The permission page is what counts.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: What Goes in the Prompt?
&lt;/h3&gt;

&lt;p&gt;The prompt is the most important part, and it’s where most of the tuning happens. The full version, for both the daily digest and the Saturday look-ahead, is in the&lt;a href="https://github.com/redgeoff/memex-template/tree/main/examples/school-digest" rel="noopener noreferrer"&gt;template&lt;/a&gt;, with a table that explains each blank. Here’s a shortened version, so you can see its shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Daily school digest for [YOUR NAME]. Kids: [KIDS]. Merge new school email and
[SCHOOL APP] into one short, actionable digest covering what's new since the
previous digest.

READ: email from [SENDERS], read-only. Follow every link to the full page.
Leave out [NOISE]. Merge duplicate notices.

WRITE: the 3 most important must-dos at the very top. Then headings [SECTIONS],
each with must-dos first, then dates, then one-line notes.
Every event gets a time, or "time not listed". Work out every weekday from the
date. Never invent a detail. If two sources disagree, say so.

CALENDAR (read-only): if a must-do is already on [CALENDARS], write "Already in
calendar"; otherwise add an "Add to calendar" link. Never change a calendar.

SEND: email from [BOT EMAIL] to [DIGEST LIST] only. Never send from [YOUR EMAIL].
Send every day, even when nothing is new.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The blanks are where your family’s details go: the kids’ grades and schools, the addresses school mail comes from (e.g. the district, the PTA, the after-school club), and the noise to leave out. In our case, the noise is mostly the kids’ sports team apps, which sent 120 emails in the same six weeks that the schools sent about 200.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: What Should the Bot Never Do?
&lt;/h3&gt;

&lt;p&gt;Most of the rules are about what the bot can’t do, and each one has a reason:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Never send from your account. Covered in step 1.&lt;/li&gt;
&lt;li&gt;Never change a calendar. The bot reads the calendars and offers a link, and one of you clicks it.&lt;/li&gt;
&lt;li&gt;Never reply to the school, by email or in a school app.&lt;/li&gt;
&lt;li&gt;Never invent a detail. If a time or a place isn’t in the source, the digest says so.&lt;/li&gt;
&lt;li&gt;Work out every weekday from the date. In its first week, our bot took the day of the week from the text of a message instead of from when it was sent, and got it wrong.&lt;/li&gt;
&lt;li&gt;Never skip a source quietly. In October, our Saturday email skipped the school app without saying so, and the digest looked complete. Now, if the bot can’t check a source, a warning goes at the very top.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You don’t need to get all of these right on day one. You’ll find your own the same way I found mine, in the next step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Why Run It by Hand for a Week First?
&lt;/h3&gt;

&lt;p&gt;Before you put the bot on a schedule, run it by hand once a day for about a week, and check every digest against the original emails. You’re looking for anything it missed, anything it got wrong and anything it made up. Every time you find one, add a rule to the prompt that would have prevented it.&lt;/p&gt;

&lt;p&gt;A crash is easy to spot, since no digest shows up. A digest that looks complete but isn’t is much worse, because you trust it. Here are a few things from our bot’s last few weeks, more than two months after we started:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On November 11, the digest said our 5th grader’s parent-teacher conference looked booked, because a conference was on Mimi’s calendar. The very next day, the digest went back to saying we still needed to book one. Each run checks everything again from scratch, and the bot doesn’t remember what it concluded the day before, so it can contradict itself from one day to the next. In this case, the event on the calendar might have been the conference or a separate meeting with the same teacher, and the bot had no way to tell.&lt;/li&gt;
&lt;li&gt;On November 10, it said a sign-up for conferences was full. On November 11, the sign-up still showed open slots, so the bot corrected itself and said it couldn’t confirm either way.&lt;/li&gt;
&lt;li&gt;The schools themselves gave two different dates for a field trip, two different days for an assembly and two different start dates for a book fair. Each time, the digest flagged the conflict for us to check instead of picking a date on its own. That one is the rule working as intended!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first one is worth knowing about before you start. If the digest says something different today than it did yesterday, don’t assume today’s is right. Check the source.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvihev6fpmudox9sivddl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvihev6fpmudox9sivddl.png" alt="Two digests side by side, paraphrased. Wednesday, November 11: 5th grade conference, looks booked, there's a conference on a calendar. Thursday, November 12: 5th grade conference, still needs booking. Below: when today's digest disagrees with yesterday's, check the source" width="800" height="320"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Two digests a day apart, paraphrased.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: How Do You Put It on a Schedule?
&lt;/h3&gt;

&lt;p&gt;Once a week goes by without a new mistake that matters, put it on a schedule. You don’t need to find a button for this. In Grok Bot, I asked the bot in chat to set up a daily routine and a Saturday routine, and they show up in the Routines list when you click the bot’s name. Ours runs every day at about 4 PM, after the schools have sent their mail, and the look-ahead runs on Saturdays at about 5 PM.&lt;/p&gt;

&lt;p&gt;One rule I changed after about eight weeks: send an email every day, even when nothing is new. At first, our bot stayed silent on quiet days, so that an email from it always meant there was something to read. The trouble is that a quiet day looked exactly the same as a broken bot. Since November 2, a quiet day gets a short “nothing new” email that lists what the bot checked: the email, the school app and the calendars. The one exception is a quiet Saturday, because the weekly look-ahead covers it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7s44zbzmsi74hkhi29fr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7s44zbzmsi74hkhi29fr.png" alt="An illustrative quiet-day email: School digest, Thursday, October 22: nothing new today. What I checked: email from school senders since Wednesday, October 21, 4:00 PM, nothing new; the school app, signed in, newest message Monday, October 19; calendars, yours, your partner's and the family calendar" width="799" height="293"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;An illustrative quiet-day email. It proves the bot ran.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What About School Apps With No Email?
&lt;/h3&gt;

&lt;p&gt;Our schools also use &lt;a href="https://talkingpts.org/" rel="noopener noreferrer"&gt;TalkingPoints&lt;/a&gt;, an app for announcements and teacher messages that never reaches email. It has no API, i.e. no official way for a program to read it, so the bot reads it the way a person would, in the web browser on its own cloud computer, and it stays signed in between runs.&lt;/p&gt;

&lt;p&gt;Signing in takes a code sent by text message to a phone number the school manages. When the session runs out, the bot puts a note at the top of the digest asking me to sign in, and still sends what it found in email. In Grok Bot, I click “Open computer”, take over the bot’s screen, type in the code from my phone and hand control back. If your school uses an app like this, start with email only, and add the app once the email digest is working.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where Should You Keep the Prompt?
&lt;/h3&gt;

&lt;p&gt;Keep a copy of the prompt somewhere outside the service, e.g. in a document, and update it every time you add a rule. If the service changes or goes away, the prompt is the bot. Without it, you’d be rebuilding a few weeks of lessons from memory.&lt;/p&gt;

&lt;p&gt;If the bot turns into something you rely on, and you’re comfortable with git (a tool that keeps the full history of every change to a folder of files), you can go a step further. My bots each have a profile in a repo, with the prompt, what the bot can access and every lesson so far. I wrote about that in&lt;a href="https://redgeoff.com/posts/stopped-re-explaining-myself-to-ai/" rel="noopener noreferrer"&gt;my post on the memex&lt;/a&gt;, and the&lt;a href="https://github.com/redgeoff/memex-template" rel="noopener noreferrer"&gt;memex-template&lt;/a&gt; repo has a starting point.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>automation</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>My tests all passed. The broker disagreed.</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Mon, 09 Nov 2026 18:58:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/my-tests-all-passed-the-broker-disagreed-1hma</link>
      <guid>https://dev.to/redgeoff/my-tests-all-passed-the-broker-disagreed-1hma</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdbplghmxtqe96b05lgsk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdbplghmxtqe96b05lgsk.jpg" alt="Two cards under the headline My tests passed. The broker disagreed. The left card, My tests, lists lint, type checks, unit tests, integration tests, a 100-run soak and snapshots, all marked pass. The right card, Me vs. the broker, shows positions and cash as matching and corporate actions as differing, stamped MISMATCH in red" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: author, drawn with code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is a story about the bugs my tests couldn’t find, and the check that found them anyway. TopSet is the trading system I built and run on my own accounts. It picks stocks with machine-learning models, rebalances on a schedule and places real orders through two brokers, Alpaca and Tradier. AI agents wrote most of the code, and&lt;a href="https://redgeoff.com/posts/ai-agents-test-gate/" rel="noopener noreferrer"&gt;my first post about it&lt;/a&gt; described the test gate that decides what merges: thousands of tests, a weekly 100-run soak and a few results I refuse to let change quietly.&lt;/p&gt;

&lt;p&gt;That gate still matters, but over time I learned that each kind of test answers a different question, and none of them answers the one I care about most: do my records match the broker’s? A mock broker can only repeat what I believe about the real one. The bugs that got furthest were the ones where my belief was wrong, and the thing that caught them was a boring comparison that runs every day after trading.&lt;/p&gt;

&lt;p&gt;So let’s take a look at what each layer caught, and then at what only the broker could tell me.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Question Does Each Test Answer?
&lt;/h2&gt;

&lt;p&gt;Here is the short version, with the longer stories below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr4tuwcltzewo1zq59d1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr4tuwcltzewo1zq59d1x.png" alt="Seven rows, each a kind of test and the question it answers. Lint and type checks: is the code well formed? Unit tests: does each piece do what I believed it should? Integration tests: do the pieces work together when the timing is awkward? The soak: does it work every time, or only usually? Snapshot tests: did the model's output change? Leakage checks: can the model see the future? These six are bracketed as checked against what I believe. The last row, reconciliation, asks whether my books match the broker's, and is bracketed in green as checked against the broker, daily." width="800" height="415"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The first six check the code against what I believe. Only reconciliation checks against the outside world.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The first six check my code, either on every pull request or in a weekly run. The last one runs in production, and it is the only one that talks to the real world.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Actually Failed in CI?
&lt;/h2&gt;

&lt;p&gt;CI, short for continuous integration, is the set of checks that runs on every pull request (a proposed change) before it can merge. Before an agent pushes a change, it runs the same lint and type checks and most of the tests on its own machine, and fixes whatever fails there. Those local failures aren’t recorded anywhere, but I’d guess there were many more of them than in CI. So CI is a second line, and the interesting question is what still got past the first one. Over four months, TopSet had about 440 pull requests, and about 1 in 9 of them still hit at least one failed build in CI. Counting every build, reruns included, 53 failed. Type checking stopped 26 of them, the tests 14 and lint 12, and one never got as far as starting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fssgdyd13ssfc5lnurye4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fssgdyd13ssfc5lnurye4.png" alt="Horizontal bar chart of the first check that failed in each of 53 failed pull-request builds over four months, reruns included: type checking 26, tests 14, lint 12, and 1 build that never started." width="800" height="436"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Which check stopped each failed build over four months of pull requests.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Those numbers need some care. The steps run in order, so a lint failure hides any test failure behind it. A rerun replaces a failed result, so I counted every attempt; only one failure was hidden that way, and it was a real bug I’ll come back to below. Builds that were canceled because a newer push replaced them aren’t counted as failures. And the local run skips the slow and integration tests, so a test failure in CI is often one that couldn’t have shown up locally. A lint or type failure in CI usually means the local check was skipped or ran against something different.&lt;/p&gt;

&lt;p&gt;I was curious whether the type checker was catching real bugs or just complaining, so I sampled a dozen type-check failures. One was a real bug: a function returned tuples where its callers expected strings, which would have failed as soon as that code ran. The rest were mostly annotations that didn’t match what pandas and numpy actually return. In other words, type checks mostly catch sloppiness and occasionally catch a real bug, and since agents produce a lot of code quickly, catching the sloppiness is worth it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Did the Integration Tests Find?
&lt;/h2&gt;

&lt;p&gt;The integration tests drive a full rebalancing against a mock broker that fills orders at random times, in random pieces, at random prices. That randomness is the point, because the interesting bugs live in the timing.&lt;/p&gt;

&lt;p&gt;The best example was a race in how the system worked out how much cash it had to spend. It read the cash balance and the cost of orders that had already filled, and subtracted one from the other. The problem was that a fill could be recorded between those two reads, because the code that recorded fills and the code that planned purchases held different locks. When that happened, the same cash was counted as available twice, and the bot tried to spend more than it had. The cash position would have gone negative, but a database rule (cash can never be below zero) stopped it.&lt;/p&gt;

&lt;p&gt;The first CI run on that pull request failed. The rerun passed. If I had treated it as a flaky test and moved on, the bug would still be there. A test that fails only sometimes is usually reporting a bug that happens only sometimes.&lt;/p&gt;

&lt;p&gt;Another came from the scheduled weekly run rather than from a pull request. Some integration runs had slowed to about half an hour. The cause was that the code placing trades retried every error, including ones that could never succeed, like a record that didn’t exist. Each hopeless retry tied up a worker for about 25 minutes. The fix, made with Cursor, retries only the errors that can actually clear up.&lt;/p&gt;

&lt;p&gt;Running the integration tests over and over found the rarer cases: one lock race that showed up once in 223 runs, and an 11-minute stall in 2 of 144 runs that turned out to be a timeout in how the test shut down its workers. I won’t retell the rest here, as &lt;a href="https://redgeoff.com/posts/ai-agents-test-gate/" rel="noopener noreferrer"&gt;the first post&lt;/a&gt; covers the soak.&lt;/p&gt;

&lt;h2&gt;
  
  
  What About Snapshot Tests?
&lt;/h2&gt;

&lt;p&gt;A snapshot test trains a model on a fixed set of data and compares its picks with a reference file that is checked into the repo. If anything about the training changes, the picks change, and the test fails.&lt;/p&gt;

&lt;p&gt;After I changed the machine-learning code, the snapshots often didn’t match. Most of the time the right move was to fix the code, because the change had done something I didn’t intend. Sometimes the right move was to update the snapshot, but only when the difference was one I expected and understood. Most of this happened on my own machine before a pull request existed, so there isn’t much of a record of it.&lt;/p&gt;

&lt;p&gt;There is one good example in the record, though. A company that had been renamed was showing up in the historical stock universe under both its old and new tickers, so on some dates the model held it twice and gave it double the weight. When we fixed the universe, the snapshot test failed, and the difference in the reference files showed exactly why: the old files had held one company under two names. That was a case where updating the snapshot was the right call, because the old snapshot had been wrong all along.&lt;/p&gt;

&lt;p&gt;The leakage checks get one line here because&lt;a href="https://redgeoff.com/posts/trading-model-leakage/" rel="noopener noreferrer"&gt;another post&lt;/a&gt; tells that story: train on part of the data, continue on the rest, and the picks must match training on all of it from scratch, bit for bit. If they don’t, something is leaking from the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  So What Couldn’t the Tests Know?
&lt;/h2&gt;

&lt;p&gt;Every test above checks the code against what I believe. The unit tests encode what I think a function should do, and the mock broker encodes what I think the real brokers do. When my belief is wrong, the code and the test are wrong together, and they agree.&lt;/p&gt;

&lt;p&gt;What I learned about the real brokers is that they do things you would never think to put in a mock. One reuses an error code for two unrelated errors. Another accepts an order and rejects it later. The code for that second broker had been written against its sandbox, a test environment, and production behaved differently. My tests matched what I believed the brokers did.&lt;/p&gt;

&lt;p&gt;So the check I rely on most compares my records with the broker’s. After trading each day, the system adds up each bot’s positions in my database and compares them with the positions the broker reports for that account. When it processes corporate actions, like mergers, splits and dividends, it also compares what each bot recorded with the account activity the broker reported. Any difference it can’t explain is an error, and errors send an alert to my phone.&lt;/p&gt;

&lt;p&gt;Here are some of the times those comparisons found something, followed by one time an audit of my own missed something.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Assumption Nobody Had Tested
&lt;/h3&gt;

&lt;p&gt;When a company is bought for cash, shareholders give up their shares and receive cash. My code booked the cash but left the shares in place, because it assumed the broker always sent a separate stock event that removed them. That’s true when a deal pays partly in stock, but in a pure cash deal there is no stock event. No bot had ever held a company in a pure cash deal before, so the assumption had never been tested, and the first one to touch a bot broke it.&lt;/p&gt;

&lt;p&gt;The tests passed, because they were built on the same assumption. The reconciliation failed the same day, because the broker’s account activity showed the shares leaving and my bot’s records didn’t. The fix removes the shares when there’s no stock event to do it, and it was checked against all 108 cash mergers in the production data rather than just the one that broke.&lt;/p&gt;

&lt;h3&gt;
  
  
  One Broker Runs a Day Behind
&lt;/h3&gt;

&lt;p&gt;That same merger exposed a second problem. Alpaca reported the account activity on the same day it changed the position. Tradier changed the position about a day before it reported the activity (up to two weeks for some corporate actions). Until the activity arrived, my system hadn’t applied the merger, so the reconciliation saw a mismatch.&lt;/p&gt;

&lt;p&gt;The quick fix was to tolerate mismatches on a symbol with a corporate action still pending. That turned out to be too generous, because it would also hide an unrelated mismatch on the same symbol, so the tolerance now requires the broker’s quantity to be exactly what the pending action predicts.&lt;/p&gt;

&lt;p&gt;The follow-up found something worse than a false alarm. While the activity was pending, a Tradier bot could plan trades from the old quantity. So symbols with a pending corporate action are now frozen during a rebalancing: not priced, not traded and not counted.&lt;/p&gt;

&lt;h3&gt;
  
  
  A False Alarm That Found a Real Problem
&lt;/h3&gt;

&lt;p&gt;One day after trading, the reconciliation reported 10 mismatches in a live account. On a system that trades real money, that reads as your records being wrong in 10 places.&lt;/p&gt;

&lt;p&gt;Alarms like this are always scary on the surface. Even with the best safeguards in place, there’s always a chance that something has gone wrong. This time I wasn’t too worried, because the totals in my account were still roughly what I expected, so I had a good feeling it was an accounting problem rather than missing money. In other words, there was a second, cruder reconciliation running in my head.&lt;/p&gt;

&lt;p&gt;That feeling was right. The broker had renamed a company that day, but my list of stocks came from a source that hadn’t caught up yet, so a bot tried to buy the old ticker. The broker rejected the order, the order got stuck, and the rebalancing never finished. The reconciliation then compared the last finished day in my database with a broker account that already showed the 10 orders that had filled that day.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fylcfnt0auogqwlxzal80.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fylcfnt0auogqwlxzal80.png" alt="Four steps from left to right: a company gets a new ticker, but my stock list still has the old one; a bot buys the old ticker, the broker rejects it and the order is stuck; the rebalancing never finishes, though its other orders have already filled; the audit compares my last finished day with the broker's today. Below: 10 mismatches reported, exactly the 10 orders that had filled that day. The positions were fine." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;How a renamed company became 10 false mismatches and one real hung rebalancing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So the alarm’s diagnosis was wrong, but the alarm was still worth having, because a rebalancing was hung and the alarm made sure I looked. The fix makes the stock list follow the broker’s renames and makes sure a rejected ticker can’t hang a rebalancing.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Audit That Looked for the Wrong Thing
&lt;/h3&gt;

&lt;p&gt;Checks like these have blind spots too, and the best example is an audit I had built for exactly the kind of problem it then missed.&lt;/p&gt;

&lt;p&gt;TopSet has a report that compares what the model planned with what the bots actually got. Once, a missing price made one of its key numbers come out blank. An agent added an audit that warned whenever that number was missing, along with seven unit tests for it.&lt;/p&gt;

&lt;p&gt;Later, a company that had recently been spun off had a gap of 10 trading days in its prices, and two bots I was comparing both held it. This time the missing price arrived as NaN (“not a number”) instead of an empty value. In Python, NaN counts as true, so the guard that should have skipped the missing price let it through, and that one value wiped out the whole day’s average for every other stock. The result was written as the text “nan”. The audit was checking for an empty value, so it let “nan” straight through. The report’s main numbers were usable on only 0 or 1 of about 13 days, with no warning, and the audit and its tests all passed. It was found by hand, by going through the per-stock data looking for missing prices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm4cu78iigqt0b7ukbmwv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm4cu78iigqt0b7ukbmwv.png" alt="An illustration with made-up returns for ten equal holdings, one of which is NaN. Three boxes follow. The guard, if not price: skip, doesn't skip it because NaN counts as true. The day's average becomes the text nan, when it should have been +0.48 percent, the average of the other nine. The audit, if result is None: warn, passes it because the text nan isn't None. The audit and its seven unit tests all passed, and nothing warned." width="800" height="477"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;How one missing price wiped out a whole day, shown with made-up numbers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Looking back, I don’t think this kind of failure can be caught up front. You need the unexpected data to show up, then you trace through the calculations, and something like an unexplained outlier tips you off. That’s why iterating on the tests matters so much: every edge case that breaks a pipeline becomes the next test, because an audit only checks what you pointed it at.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Does It Cost?
&lt;/h2&gt;

&lt;p&gt;Reconciliation isn’t free. It raises false alarms, like the renamed ticker and the broker that runs a day behind, and every false alarm is a choice between investigating and loosening a tolerance. Loosen it too far and it stops catching anything, which is why the pending-action tolerance had to be tightened again. Each new kind of corporate action also needs its own rules for what the broker should show, and those rules are code with their own bugs.&lt;/p&gt;

&lt;p&gt;That being said, I’d make the same trade again. A false alarm costs me some time. A silent mismatch between my books and the broker’s could cost real money, and it would keep growing until something else noticed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Can It Run Unattended?
&lt;/h2&gt;

&lt;p&gt;The tests decide what merges. The reconciliation decides whether I can leave the system alone, and that’s a different question. A one-person system can’t depend on someone watching it every day. It has to notice when it’s wrong and say so.&lt;/p&gt;

&lt;p&gt;Here is what I’d tell anyone building something like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use each kind of test for the question it answers, and don’t expect any of them to tell you what the outside world does.&lt;/li&gt;
&lt;li&gt;Treat a test that fails sometimes as a bug report, and don’t just rerun it until it passes.&lt;/li&gt;
&lt;li&gt;Compare your records with the outside system’s every day, and make any difference you can’t explain an error that reaches you.&lt;/li&gt;
&lt;li&gt;When a check misses something, ask what else it isn’t looking for.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;TopSet runs unattended today because of that last layer. When something drifts, the broker disagrees with me, and I hear about it the same day.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This describes software I run on my own accounts. It is not investment advice and I do not offer investment services.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>testing</category>
    </item>
    <item>
      <title>I stopped re-explaining myself to AI</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Tue, 03 Nov 2026 00:20:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/i-stopped-re-explaining-myself-to-ai-1gbp</link>
      <guid>https://dev.to/redgeoff/i-stopped-re-explaining-myself-to-ai-1gbp</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjxijigqgkj8b12j5i06g.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjxijigqgkj8b12j5i06g.jpg" alt="Five labels on the left, Claude Code, Grok Bot, School bot, Memex bot and Another AI, with arrows into one card labeled memex/ that lists INDEX.md, decisions.md, knowledge/, context/, bots/ and dreams/, under the headline One memory, every AI" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: author, drawn with code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For a while, every new AI session started with me re-explaining things: who I am, what I’m working on and which documents matter, often by uploading the same PDFs again. Now any AI I use starts with all of that.&lt;/p&gt;

&lt;p&gt;This is a story about how I moved my notes out of Google Drive and into a folder of plain text files that every AI I use can read and update, and about the handful of rules that keep that folder from turning into a mess. I call it my memex.&lt;/p&gt;

&lt;p&gt;If you read &lt;a href="https://redgeoff.com/posts/school-email-bot/" rel="noopener noreferrer"&gt;my last post&lt;/a&gt;, you’ve already met it. The bot that reads our kids’ school email keeps its rules there. This post is about the memex itself: what’s in it, how it stays accurate when several AIs are writing to it, and how you could start one.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Was Wrong With Google Drive?
&lt;/h3&gt;

&lt;p&gt;In short, AIs kept tripping over my documents. When I pointed Claude at my Google Drive and asked it to edit a Google Doc, it would create a new copy instead of changing the one I had. Claude has its own documents that it can edit, but other AIs can’t easily read them. And most AIs couldn’t search my Drive well enough to find things, so I often ended up exporting documents to PDF and uploading them by hand.&lt;/p&gt;

&lt;p&gt;I wanted one place that any AI could read, search and change, without me copying things around. A note-taking app wasn’t the answer either, since you’re limited to the structure and features the app gives you.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Is the Memex?
&lt;/h3&gt;

&lt;p&gt;The name comes from Vannevar Bush’s 1945 essay “As We May Think”, where a memex is a desk that stores a person’s books, records and communications so they can be consulted quickly. Mine is a git repo of markdown files. Markdown is plain text with a little formatting, e.g. a &lt;code&gt;#&lt;/code&gt; in front of a heading. A git repo is a folder that records every change, so you can see what changed, when and why, and undo any of it. Mine lives on my laptop and in a private repo on GitHub.&lt;/p&gt;

&lt;p&gt;The files are organized by what they’re about:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;knowledge/&lt;/code&gt; holds the notes: my career history, projects, reference material, the household (school schedules, the cars, recipes) and a daily log.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;context/&lt;/code&gt; holds a few files that tell an AI who I am and how I like to work, e.g. “ask me instead of guessing” and “never commit directly to main”.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bots/&lt;/code&gt; holds a profile for each bot, which is what my last post was about.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;scripts/&lt;/code&gt; and &lt;code&gt;skills/&lt;/code&gt; hold the small programs that check and maintain everything, with their tests.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I created the repo on March 1, 2026 from a template and then mostly forgot about it. The real work started on October 13, 2026. As of October 31, it has 131 notes and about 157,000 words.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmkh6xng3bm0938xqloka.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmkh6xng3bm0938xqloka.png" alt="Line chart of words in the memex by day, October 12 to 30, 2026: 7 notes and about 3,000 words in the template, 27 notes after the Google Drive import on October 13, 79 notes on October 14, then a slower climb to 131 notes and about 157,000 words, with dreams marked on October 13, 15 and 25" width="800" height="462"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Words across all notes at the end of each day. Most of the jump came in the first two days.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How Did My Drive Get Into It?
&lt;/h3&gt;

&lt;p&gt;On October 13, I downloaded my Google Drive to my laptop and had Claude read it. It extracted the text from about 780 files: PDFs, Word documents, slide decks, spreadsheets and plain text. Google Docs were the one snag. They sync to a laptop as pointer files with no text in them, so I downloaded those folders again as Word and Excel files. Claude then read the converted files too and summarized everything it had read into notes, mostly about my career and past projects, rather than copying the documents in.&lt;/p&gt;

&lt;p&gt;Some things I didn’t want in the memex at all, so before anything was summarized we agreed on what to leave out: tax and financial records, anything that looked like it held a password, medical and identity documents, and the folders about our kids. The memex keeps a ledger of the import that lists what was read, what was skipped and why. That way a later session doesn’t redo the work, or worse, import something I had already decided to exclude.&lt;/p&gt;

&lt;p&gt;The import surfaced something I hadn’t expected. When you read 25 years of someone’s documents side by side, they disagree with each other. For example, one of my old self-reviews said our hotfixes had dropped from 8 a week to 1.5, while my other records said 7. Rather than pick one, Claude listed every conflict like that and asked me. I answered them in batches that day, and each answer became an entry in a decisions log.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmaf1c25iuyrn5tvnrtuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmaf1c25iuyrn5tvnrtuh.png" alt="Three boxes: documents disagree (a self-review said hotfixes fell from 8 a week to 1.5, other records said from 7), I decide (decision D13, 7 to 1.5 a week, not 8), and the checker holds it (a note that says 8 to 1.5 fails the check and cites D13)" width="800" height="320"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;One conflict from the import, from my documents to a rule the checker enforces.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How Does It Stay Accurate?
&lt;/h3&gt;

&lt;p&gt;A pile of notes that several AIs write to will drift. One session restates a fact a little differently, another copies an old number from a document, and a month later nobody knows which version is right. So the memex has a few rules, and a program checks most of them on every change.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0v9jgf4q45dap4buyjtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0v9jgf4q45dap4buyjtg.png" alt="An example note header with date, updated, tags, status, summary and sensitivity fields, each labeled with what it is for" width="800" height="443"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;An example header. The index is built from these lines.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Every note starts with a short header: when it was created and last updated, some tags, whether it’s active or a draft, a one-line summary and how private it is. Private notes never leave the memex. Usable notes can inform things I write, like this post. Public notes are already public.&lt;/li&gt;
&lt;li&gt;A script builds an index from those headers, one line per note. An AI reads the index first and then opens only the notes it needs. That matters because an AI can only hold so much text at once (its “context window”), and 157,000 words is far more than you’d want it to load for every question.&lt;/li&gt;
&lt;li&gt;The decisions log records each of my rulings with its date, 42 of them so far. Old decisions are never edited. A new one says which one it replaces.&lt;/li&gt;
&lt;li&gt;Some decisions are backed by a rule in the checker, so a corrected fact can’t creep back in. If a note says hotfixes went from 8 to 1.5 a week, the check fails and points at the decision.&lt;/li&gt;
&lt;li&gt;The checker, or linter, also makes sure every note has its header, every link points to a real note, file names follow one pattern, nothing looks like a password or an access key, and the index is current. It runs on every change, along with 196 automated tests for the scripts.&lt;/li&gt;
&lt;li&gt;Every change arrives as a pull request, which is a proposed change I can read before it’s accepted. Nothing is committed straight to the main copy. For the memex, I let the AI merge its own pull request once the checks pass.&lt;/li&gt;
&lt;li&gt;Nothing is deleted. Notes that are out of date move to an archive folder.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of this is clever. The rules are simple enough that any AI can follow them, and the checker catches it when one doesn’t.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Is the Dream?
&lt;/h3&gt;

&lt;p&gt;The checker can tell you a link is broken, but it can’t tell you that two notes say the same thing in different words, or that a plan from three weeks ago is stale. For that, there is a cleanup pass called a “dream”, loosely after the way sleep is thought to consolidate memories.&lt;/p&gt;

&lt;p&gt;I didn’t come up with the idea. Anthropic added&lt;a href="https://claude.com/blog/new-in-claude-managed-agents" rel="noopener noreferrer"&gt;dreaming&lt;/a&gt; to Claude Managed Agents in May 2026: a scheduled process that reviews an agent’s past sessions and memory, pulls out patterns and tidies the memory, either on its own or with you reviewing the changes first. Their Code with Claude talk,&lt;a href="https://claude.com/code-with-claude/session/sf-memory-and-dreaming-for-self-learning-agents" rel="noopener noreferrer"&gt;“Memory and dreaming for self-learning agents”&lt;/a&gt;, covers how they got there. &lt;a href="https://docs.openclaw.ai/concepts/dreaming" rel="noopener noreferrer"&gt;OpenClaw&lt;/a&gt; has its own version that runs in light, REM and deep phases and writes a diary of what it changed, and &lt;a href="https://hermes-agent.nousresearch.com/docs/plugins/hermes-dreaming" rel="noopener noreferrer"&gt;Hermes Agent&lt;/a&gt; has a community plugin modeled on OpenClaw’s. Mine borrows from all of them. The difference is that my memory is a git repo, so a dream’s changes arrive as a pull request I can read.&lt;/p&gt;

&lt;p&gt;A dream has two halves. The mechanical half runs the checker and rebuilds the index. The reflective half is an AI working through a written checklist: promote anything durable from the daily log into the right note, find facts stated in more than one place and keep one owner for each, flag notes that have gone stale, and write down the questions only I can answer. It lands as a pull request with a short report.&lt;/p&gt;

&lt;p&gt;What the AI is allowed to do on its own depends on the change:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mechanical fixes that don’t change meaning, like a broken link or a stale index, it just does.&lt;/li&gt;
&lt;li&gt;Moves, merges and new notes, it makes on the branch and calls out in the report, so I can accept or revert them.&lt;/li&gt;
&lt;li&gt;Anything that changes what a fact means, which version of something is right, or a privacy rule, it asks me about first and doesn’t touch until I answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fygh83cg4nzdcjk2bzx39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fygh83cg4nzdcjk2bzx39.png" alt="Three columns: just does it (rebuild the index, fix a broken link, tidy a header), proposes in the PR (merge two notes, move a note, promote a daily-log fact) and asks me first (which version is right, a recorded decision, a privacy rule)" width="800" height="382"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;What a dream may do on its own, what it proposes and what it asks about.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There have been four dreams so far: October 13, October 15, October 25 and November 1. The last two were run by a bot on its own weekly schedule. On October 25, lint was already clean, so the main results were notes for the two people mentioned most often who didn’t have one yet (notes on people are private and stay in the memex), and one place where the repo’s instructions contradicted a newer decision. The November 1 dream was lighter: one lint warning fixed, the bot’s own log brought up to date and no questions for me.&lt;/p&gt;

&lt;h3&gt;
  
  
  Who Writes to It?
&lt;/h3&gt;

&lt;p&gt;More than one AI, which was the whole idea. From October 13 to 31, the memex had 190 commits and 122 merged pull requests. Most came from Claude Code sessions on my laptop. Others came from Grok Bot, the agent I use to run bots on a cloud computer, and from the bots themselves, e.g. the school bot updating its profile and a memex bot that does the weekly upkeep.&lt;/p&gt;

&lt;p&gt;Two things fall out of that. First, I’m not tied to any one AI. If I switch tools tomorrow, the notes, the rules and the history come with me, because they’re just files. Second, every session starts with context. I don’t paste my background into a prompt or explain how something works, because the AI reads the index and finds it.&lt;/p&gt;

&lt;p&gt;In practice, I start most things with that same memex bot. When I want to add to something or work on it, like a new project idea, a blog post I should write or a book I should read, I ask the memex bot to add the details. It already has the context of many things in my life, both current and old. And when I’m working in another AI and I think my memex would help, I give that AI read and write access to the memex’s GitHub repo, and it has the same context right away. A bot gets its own access token that works only on that one repo, can only read and write files and open pull requests, and expires within 90 days.&lt;/p&gt;

&lt;p&gt;Pull requests turned out to be useful for more than catching an AI’s mistakes. When I want feedback on a document, I open it as a pull request and leave comments on specific lines in GitHub, the way you’d review code. The AI answers each comment and pushes a new version. This post was reviewed that way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is It Safe?
&lt;/h3&gt;

&lt;p&gt;I think it’s relatively safe, as long as you don’t have a lot of automations that send out or post content unattended. The only bot of mine that emails anyone sends to one family list, from its own account; the others open pull requests or message me in a private Slack channel. That said, there are risks, and you certainly don’t want to store anything sensitive in your memex, e.g. credit card numbers. The checker flags anything that looks like a password or an access key, but it can’t catch everything, so the better habit is to leave those things out in the first place.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Would I Do Differently From Day One?
&lt;/h3&gt;

&lt;p&gt;Not much, and I wouldn’t try to design it all up front. Everyone’s preferences differ, and mine weren’t clear until I’d used it for a while. A memex changes shape as you use it, and the goal is that over time it holds all of your context and preferences, written down.&lt;/p&gt;

&lt;p&gt;That said, three things would have saved me some cleanup:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start the decisions log on day one, not after the import.&lt;/li&gt;
&lt;li&gt;Decide what stays out, e.g. financial and medical records, before an AI reads anything.&lt;/li&gt;
&lt;li&gt;Add the index before the notes pass a few dozen.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How Could You Start One?
&lt;/h3&gt;

&lt;p&gt;You don’t need my scripts to get most of the benefit. A folder of markdown files in a git repo, a short header on every note and an AI that can read files will get you a long way. I’d add the rest in roughly the order it paid off for me:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A context file that says who you are and how you like to work.&lt;/li&gt;
&lt;li&gt;The header on every note, and an index built from the headers.&lt;/li&gt;
&lt;li&gt;A decisions log, as soon as you catch yourself correcting the same fact twice.&lt;/li&gt;
&lt;li&gt;A checker that runs on every change.&lt;/li&gt;
&lt;li&gt;Changes by pull request, so you see what an AI did before it sticks.&lt;/li&gt;
&lt;li&gt;A cleanup pass once the notes outgrow what you can review by hand.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you’d like a head start, I’ve put the memex’s structure and tooling on GitHub as a template, with none of my notes in it:&lt;a href="https://github.com/redgeoff/memex-template" rel="noopener noreferrer"&gt;memex-template&lt;/a&gt;. It has the folders, the note header, the index builder, the checker, a decisions log with an example rule, and the dream protocol with its &lt;code&gt;/dream&lt;/code&gt; command. The bot template from my last post lives there too, since the bots deliver into the memex.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I built an AI bot to read our kids' school email. Here's what I'd tell you before you build one.</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Mon, 26 Oct 2026 22:33:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/i-built-an-ai-bot-to-read-our-kids-school-email-heres-what-id-tell-you-before-you-build-one-42me</link>
      <guid>https://dev.to/redgeoff/i-built-an-ai-bot-to-read-our-kids-school-email-heres-what-id-tell-you-before-you-build-one-42me</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Favuoab2upy0vbetzxefh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Favuoab2upy0vbetzxefh.jpg" alt="A pile of tilted cards labeled Newsletter, Reminder, Flyer, Form due and other school messages on a dark background, with an arrow to a single School digest page with Must-do, This week and Coming up sections" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: author, drawn with code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is a story about how my wife and I went from several school emails and texts a day to one short digest every afternoon, and about what it took to trust an AI bot to write it. Getting the bot to summarize was the easy part. Most of the work went into deciding what it is not allowed to do, and into catching the times it got something wrong without saying so.&lt;/p&gt;

&lt;p&gt;If you read &lt;a href="https://redgeoff.com/posts/ai-agents-test-gate/" rel="noopener noreferrer"&gt;my first post&lt;/a&gt;, this is the same idea in a very different setting. There, automated tests were the gate that let AI agents write code for a system that trades real money. Here, the gate is a short list of things the bot can never do, plus one place where every rule it follows is written down.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Build a Bot for School Email?
&lt;/h3&gt;

&lt;p&gt;We have two kids at two different schools, a 5th grader and a 2nd grader. Between the district, both schools, the teachers, the parent groups, the after-school club and the flyers, the messages never really stop. We were getting multiple emails and texts a day, and I figured a bot would be a good way to consolidate the noise.&lt;/p&gt;

&lt;p&gt;I counted afterwards. In the six weeks from September 9 to October 21, 2026, roughly 200 emails came in that were actually about school, or a bit over 30 a week. Over the same weeks, the kids’ sports team app sent another 120. Some of the school mail is duplicated, too, e.g. the after-school club often sends the same notice once for each kid.&lt;/p&gt;

&lt;p&gt;On top of that, the schools use &lt;a href="https://talkingpts.org/" rel="noopener noreferrer"&gt;TalkingPoints&lt;/a&gt;, an app for school announcements and teacher messages, and those never reach email at all. In one sample week it had about 13 announcements and 3 active conversations with teachers. In other words, keeping up meant reading all of that email and then remembering to open a separate app every day.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpo6o8c2pgm1l0lnypvh4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpo6o8c2pgm1l0lnypvh4.png" alt="Horizontal bar chart: about 200 school emails in, 120 sports team app emails left out, and 44 digests sent, September 9 to October 21, 2026" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Six weeks of school messages. TalkingPoints isn’t in the count, because it never reaches email.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What Does the Bot Actually Do?
&lt;/h3&gt;

&lt;p&gt;Every afternoon, the bot reads the new school mail in Gmail and the new messages in TalkingPoints. It follows the links to the full newsletters instead of trusting the preview in the email, and then it writes one digest. Everything is grouped by school, with the must-dos first. Every event has a time, or says “time not listed” rather than a guess. A notice that was sent once per kid shows up once, and the sports team mail is left out. On Saturday evenings, a second email looks ahead at the next few weeks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp1rac0m4psdic4cbqr0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp1rac0m4psdic4cbqr0w.png" alt="An illustrative school digest with must-dos first, an Add to calendar tag, Already in calendar tags, a section per grade and a coming-up section" width="800" height="550"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;An illustrative digest with made-up items, to show the format. The real ones are private.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Before it writes, the bot also checks my Google Calendar. If a must-do is already on it, the digest says “Already in calendar”. If it isn’t, the item gets an “Add to calendar” link, so adding it takes one click. And if nothing new came in, the bot sends nothing at all, so an email from it always means there’s something to read.&lt;/p&gt;

&lt;p&gt;The digest goes from the bot’s own Gmail account to a mailing list that Mimi and I share. From September 9 to October 20 it sent 44 digests, 40 daily and 4 weekly. That’s about 7 emails a week in place of 30-plus emails and an app. I’d estimate it saves me 30 to 45 minutes of reading a week.&lt;/p&gt;

&lt;p&gt;We both read the digest every day, and it has cut down the time I spend keeping up with all the notifications. Another benefit is that my day has far fewer interruptions. Instead of switching over every time an email or a message comes in, I let them pile up and read them all at once in the digest. It has also made it less likely that something falls through the cracks, and the calendar links have made it easy to keep my calendar up to date. Mimi and I share our calendars with each other, so whatever I add, she can see too.&lt;/p&gt;

&lt;p&gt;Here are a few of its catches from the first six weeks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A school event that was posted only in TalkingPoints, with the details on a linked newsletter page. Reading email alone would have missed it.&lt;/li&gt;
&lt;li&gt;Two notices gave different dates for the same family night, and the later date was the same evening as an event at the other school. The digest flagged it so we could check.&lt;/li&gt;
&lt;li&gt;A calendar entry labeled with the wrong school, and another that ran half an hour longer than the school said.&lt;/li&gt;
&lt;li&gt;A newsletter that printed last year’s date for this year’s parade.&lt;/li&gt;
&lt;li&gt;A reading test on the same day as two appointments. A later teacher message showed it had already been handled, so the digest told us there was nothing to reschedule.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What Is the Bot Not Allowed to Do?
&lt;/h3&gt;

&lt;p&gt;The bot can read a lot: my Gmail, my calendar and TalkingPoints. If it could also write to all of those, one bad run could send an email in my name to a teacher, move an event on my calendar or reply in a class conversation. So most of its rules are about what it can’t do.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It never sends from my account. It has its own Gmail account, and it only sends to our shared list. It can only read my Gmail.&lt;/li&gt;
&lt;li&gt;It never creates, changes or deletes a calendar event. It reads the calendar, and one of us clicks “Add to calendar”.&lt;/li&gt;
&lt;li&gt;It never replies to the school, by email or in TalkingPoints.&lt;/li&gt;
&lt;li&gt;It never invents a detail. If a time or a place isn’t in the source, the digest says so.&lt;/li&gt;
&lt;li&gt;It works out every day of the week itself from the date. It never copies one from a message or trusts its own guess.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fomjucpuiwldjbhlp5qw4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fomjucpuiwldjbhlp5qw4.png" alt="Diagram: the bot reads Gmail and Google Calendar read-only and TalkingPoints in its own browser, sends only from its own Gmail to one shared list, and never sends as me, changes the calendar, replies to the school or invents a detail" width="800" height="418"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;What the bot can read, where it can send, and what it never does.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;TalkingPoints needed the most care. It has no API, i.e. no official way for a program to read it, so the bot reads it the way a person would, in a web browser. I run the bot on&lt;a href="https://cursor.com/docs/grok-bot/get-started" rel="noopener noreferrer"&gt;Grok Bot&lt;/a&gt;, which runs its bots on a cloud computer with a web browser, and the bot stays signed in to TalkingPoints there between runs.&lt;/p&gt;

&lt;p&gt;Signing in to TalkingPoints takes a code sent by text message to a phone number that the school manages. So, when the session expires, the bot stops and asks me to sign in. I click “Open computer” in Grok Bot, take over the bot’s screen, type in the code from my phone and hand control back. I looked into giving the bot a virtual phone number so it could read its own codes, and decided against it. The number is managed by the school, and a number the bot could read would be a key to the account. So for now, I type in the code myself, and I’ll revisit that if it starts happening often.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Went Wrong?
&lt;/h3&gt;

&lt;p&gt;Quite a bit, and the failures that matter most are the quiet ones. A crash is easy to spot, since no digest shows up. A digest that looks complete but isn’t is much worse, because you trust it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On September 11, the bot took the day of the week from the text of a message instead of from when the message was sent. By the end of September it had mixed up weekdays on its own too, so now it calculates every weekday from the date.&lt;/li&gt;
&lt;li&gt;On October 10, the weekly email skipped TalkingPoints without saying so. Now the bot has to check TalkingPoints on every run, and if it can’t, a warning goes at the very top of the digest.&lt;/li&gt;
&lt;li&gt;On October 11, a digest arrived full of raw formatting code, e.g. &lt;code&gt;&amp;lt;h3&amp;gt;&lt;/code&gt; where a heading should have been. Now a small program checks every email before it’s sent, and the bot isn’t allowed to send until the check passes.&lt;/li&gt;
&lt;li&gt;On October 15, the bot reported that TalkingPoints had signed it out. It hadn’t. The bot had judged from the app’s front page alone. A corrected digest went out the same day, and now the bot confirms a sign-out by opening a page that only a signed-in user can reach.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvh9gch7g1ua4uh200s4t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvh9gch7g1ua4uh200s4t.png" alt="Four rows, each pairing a quiet failure with the rule it became: September 11 weekday, October 10 skipped TalkingPoints, October 11 raw formatting code, October 15 false sign-out" width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The four quiet failures, and the rule each one became.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you recall from my post on &lt;a href="https://redgeoff.com/posts/backtest-noise/" rel="noopener noreferrer"&gt;random seeds&lt;/a&gt;, the dangerous results there didn’t crash either. They looked convincing. A digest that quietly skips a source is the same kind of bug, and the fix was the same kind of fix: a check that runs every time, whether or not anyone remembers it.&lt;/p&gt;

&lt;p&gt;There were plumbing problems too. In early October, the bot’s Gmail connection lost the ability to send, so it got a backup way to send email, and a week later the cloud computer blocked that backup, by which point the Gmail connection worked again. All told, 5 of the 44 digests were corrections or second versions.&lt;/p&gt;

&lt;p&gt;Every one of those lessons became a written rule. But written where?&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Do the Bots Live in a Git Repo?
&lt;/h3&gt;

&lt;p&gt;For the first five weeks, the bot’s setup, its instructions and its rules lived only on the cloud computer. If that computer had gone away, I would have had to rebuild the bot from memory. On October 14 the bot exported all of it into my memex, and that is where its rules live now.&lt;/p&gt;

&lt;p&gt;My memex is a git repo of markdown files. If you haven’t used git, a repo is a folder that records every change, so you can see what changed, when, and undo any of it. Markdown is plain text with a little formatting. The name comes from Vannevar Bush’s 1945 essay “As We May Think”, where a memex is a device in which a person “stores all his books, records, and communications”, so that it “may be consulted with exceeding speed and flexibility.” Mine is less grand than that.&lt;/p&gt;

&lt;p&gt;I started it because AIs kept tripping over my documents. I had pointed Claude at my Google Drive, and when it edited a Google Doc, it would create a new version of the document instead of changing the one I had, which got messy and tedious fast. Claude has its own documents that it can edit, but other AIs can’t easily read them. Most AIs also couldn’t search my Drive well enough to find things, so I often ended up exporting documents to PDF and uploading them by hand. A note-taking app wasn’t the answer either, since you’re limited to the structure and features the app gives you. A folder of markdown files, on the other hand, seems to be something an AI can work with natively. So I downloaded my Drive, had the AI summarize the non-sensitive parts into the memex, and now any AI I use can read and update the same notes. I also have the full history of every change.&lt;/p&gt;

&lt;p&gt;Every note starts with a short header that says what it is, when it changed and how private it is. A checker reads every note, a script builds an index of all of them, and a decisions log records each ruling with its date. 185 automated tests run on every change. There is even a cleanup pass I call “dream”, which checks, re-indexes and tidies up the notes.&lt;/p&gt;

&lt;p&gt;Each bot has a profile in the repo called &lt;code&gt;BOT.md&lt;/code&gt;. It records where the bot runs, its instructions word for word, what it has access to, the decisions it must follow and every lesson above. Changes to it arrive as a pull request, which is a proposed change I can read before I accept it, and the bot is expected to update its profile whenever its setup changes. So, if the cloud computer disappeared tomorrow, I could rebuild the bot from what’s in the repo.&lt;/p&gt;

&lt;p&gt;Having the profile has one more advantage. Because the bot already knows how it works and what was in the latest newsletters, I don’t have to explain anything when I ask it a question. I just ask, e.g. whether anything changed for a field trip, and it has the context.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Would I Do Differently From Day One?
&lt;/h3&gt;

&lt;p&gt;The school bot came first, and it grew its rules one failure at a time. The bots I’ve built since start from a template, and they go a step further: everything they produce, not just their profile, arrives in the memex as a pull request. I cleaned up that template and published it as &lt;a href="https://github.com/redgeoff/memex-bots" rel="noopener noreferrer"&gt;memex-bots&lt;/a&gt;. This part is more technical, so feel free to skim. These are its rules.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The AI finds and judges, and ordinary code decides. The AI searches with its own tools and writes down what it found. A small Python program checks that, scores it and writes the digest. Because the scores come from code, the same input always gets the same result.&lt;/li&gt;
&lt;li&gt;Every item needs a source. An item without a link and a short quote is dropped, and the digest says how many were dropped.&lt;/li&gt;
&lt;li&gt;Every run is one pull request, never a direct change. GitHub enforces that, and it also requires CI to pass first. CI, short for continuous integration, is the set of automated checks that run on every proposed change.&lt;/li&gt;
&lt;li&gt;A file named &lt;code&gt;PAUSED&lt;/code&gt; stops a bot, and a cap on unreviewed pull requests stops a bot that’s running away.&lt;/li&gt;
&lt;li&gt;A failed run still opens a pull request, with a “Run problems” section that says what went wrong. That’s the October 10 lesson, built into the template.&lt;/li&gt;
&lt;li&gt;Every bot starts as a written plan: what it’s for, how much of my time it may take each week, what’s off-limits, when to shut it down and the open questions, all before any code.&lt;/li&gt;
&lt;li&gt;Every bot gets its own GitHub access token, a key that only works on the one repo and expires on a set date.&lt;/li&gt;
&lt;li&gt;Every bot keeps its own &lt;code&gt;BOT.md&lt;/code&gt; up to date.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can try it without an AI. Download the repo and run the example, and the program runs on sample data: it writes a digest, adds a line to a log, and lists the one item with no link under “Run problems” instead of quietly using it.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Does It Take to Run Them?
&lt;/h3&gt;

&lt;p&gt;I run my bots on Grok Bot for now, because it comes with my Cursor subscription and has a web browser built in. The template doesn’t depend on Grok Bot, though. Any AI agent that can run on a schedule, read and write files, run a program and open a pull request can run these bots, and the repo has a short guide to controlling a bot from your phone through a private Slack channel.&lt;/p&gt;

&lt;p&gt;Grok Bot isn’t the only option anymore. OpenAI’s&lt;a href="https://help.openai.com/en/articles/20001530-getting-started-with-your-dot" rel="noopener noreferrer"&gt;dots&lt;/a&gt; and Meta’s &lt;a href="https://en.wikipedia.org/wiki/Muse_(AI_agent)" rel="noopener noreferrer"&gt;Muse&lt;/a&gt; are newer services that also give each AI agent a cloud computer with a browser, and each one has its own advantages when it comes to data. For example, Grok Bot appears to be able to search posts on X, and Muse can search and monitor Facebook. I’m currently using Muse to watch a Buy Nothing group for anyone giving away a golf bag.&lt;/p&gt;

&lt;p&gt;Before Grok Bot, I built “automations” with OpenClaw, and then with Hermes because it handled failures better, using OpenRouter to choose the AI model. You can do some pretty powerful things that way, but you’re ultimately limited by the model. I’ve found that useful bots still need one of the most capable models, and the best bang for your buck right now seems to be the monthly subscriptions from the leading AI labs. Open-weight models like DeepSeek, which anyone can download and run, are promising, but in my experience they weren’t really cheaper than something like Grok Bot. My guess is that the AI companies are covering some of the cost today, so that could change.&lt;/p&gt;

&lt;p&gt;Whichever service you use, I’d encourage you to build a bot for whatever keeps piling up in your inbox. Run it by hand for a few days and check every digest against the original messages before you put it on a schedule, and every time it gets something wrong, add a rule. I’m planning a follow-up post with step-by-step directions for building a school digest bot like this one. And if a bot turns into something you rely on, that’s the time to write its rules and profile down in a repo, so its memory belongs to you and it can move to the next service with you.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>llm</category>
      <category>sideprojects</category>
    </item>
    <item>
      <title>I spent 21 months building a trading system, then had AI models tell me not to start the company</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Tue, 20 Oct 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/i-spent-21-months-building-a-trading-system-then-had-ai-models-tell-me-not-to-start-the-company-3lma</link>
      <guid>https://dev.to/redgeoff/i-spent-21-months-building-a-trading-system-then-had-ai-models-tell-me-not-to-start-the-company-3lma</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3mjxx7e7dva6q6lrgydx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3mjxx7e7dva6q6lrgydx.jpg" alt="Two tilted memo pages of gray placeholder lines on a dark background, each stamped in red with the same verdict: PERSONAL ONLY" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: author, drawn with code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is a story about how I spent 21 months building a trading system, wrote down what it would take for it to become a company, and then had two AI models tell me that it hadn’t.&lt;/p&gt;

&lt;p&gt;If you’ve read my last three posts, you know TopSet. It’s the system I built, mostly with AI coding agents, to pick a portfolio of stocks with machine-learning models and trade it with real money. &lt;a href="https://redgeoff.com/posts/ai-agents-test-gate/" rel="noopener noreferrer"&gt;The first post&lt;/a&gt; was about the automated tests that made agent-written code safe to run,&lt;a href="https://redgeoff.com/posts/trading-model-leakage/" rel="noopener noreferrer"&gt;the second&lt;/a&gt; was about the ways information from the future leaked into my models, and&lt;a href="https://redgeoff.com/posts/backtest-noise/" rel="noopener noreferrer"&gt;the third&lt;/a&gt; was about noise, and ended with a promise to explain what I decided to do once I knew that my model’s results couldn’t be told apart from luck. This is that post, and you don’t need to have read the others to follow it. There are no charts of returns in it, and that’s on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Did I Give Myself a Deadline?
&lt;/h2&gt;

&lt;p&gt;I started TopSet because I saw promise in using machine learning to find patterns in the stock market, and my early results looked promising enough that I thought I had something. I also knew that a project like this can absorb years without ever answering the question it was started to answer. So, I gave myself a kill criterion, i.e., a condition, decided ahead of time, under which I would stop: about two years full time to find out whether there was a business here. If there wasn’t, I’d go back to leading engineering teams.&lt;/p&gt;

&lt;p&gt;The first live trading bot started on December 2, 2024, and I went full time in January 2025. By September 2026, the system had run continuously on live capital for almost two years, through about 1,600 pull requests (each one a reviewed change to the code), and I was close enough to the deadline that I needed an answer I could trust.&lt;/p&gt;

&lt;p&gt;To be honest, I already suspected what the answer would be. Around the beginning of the summer of 2026, I’d started to think that, measured over the long run, my results weren’t statistically strong enough to justify starting a company. But a suspicion is easy to argue yourself out of, especially when you want the other answer, so I wanted a process that would either confirm it or talk me out of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Do You Ask an AI Whether to Start a Company?
&lt;/h2&gt;

&lt;p&gt;Most of the work happened before I asked anything. The obvious way would have been to open a chat and type “here’s my trading system, should I start a company?” I’d have gotten an encouraging answer, because I’d have described the system the way founders describe their systems. Instead, on September 17, 2026, I wrote two documents first, working with a Cursor agent.&lt;/p&gt;

&lt;p&gt;The first was an index of everything in the repository: what was built, what was live, and, just as importantly, what had already been tried and abandoned. Every closed experiment was listed with its verdict and a link to where it was decided. The point was that the evaluation would start from the record, not from my pitch.&lt;/p&gt;

&lt;p&gt;The second was the evaluation itself, written as a set of gates. Each gate was a question with a written condition for failing it, so the evaluator couldn’t decide what counted as failure after seeing the answer. There were five:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Differentiation. What does a customer get here that a cheap index fund, i.e., a fund that simply holds every stock in an index like the S&amp;amp;P 500, doesn’t?&lt;/li&gt;
&lt;li&gt;Evidence. Does the case for a company rest on anything unproven, or on anything I’d already tested and abandoned?&lt;/li&gt;
&lt;li&gt;Regulatory fit. Can the product be marketed honestly within the rules for investment advisers? In the US, anyone paid to manage or advise on other people’s investments generally has to register with regulators, and there are strict rules about what they can say about performance.&lt;/li&gt;
&lt;li&gt;Economics. Can it work for one person without raising money?&lt;/li&gt;
&lt;li&gt;The personal path. Found a company, run a 90-day trial to see whether anyone would pay, keep it for my own money only, or stop and look for a job?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The differentiation gate, for example, failed if the honest pitch collapsed to “levered / concentrated market beta with model complexity attached.” Beta is how much a portfolio moves with the market as a whole. In other words, if the product was really just the stock market with extra risk and a complicated model on top, it failed. That matters because extra risk is cheap to buy: anyone can get more of the market’s ups and downs by adding a little leverage to a low-cost index fund, so a product built on that would be charging for something customers can already get cheaply.&lt;/p&gt;

&lt;p&gt;I also wrote down what the evaluator was not allowed to do. The brief at the top says “Do not treat years invested … as evidence of a company.” And a list titled “Anti-patterns (do not do these)” includes “Soften a STOP / JOB SEARCH verdict to protect sunk cost.” Sunk cost is the time and money already spent, which can’t be recovered whatever you decide next. The person most likely to want that verdict softened was me.&lt;/p&gt;

&lt;p&gt;There’s a small irony in that brief. Under go-to-market, i.e., how customers would find the product, I’d written that I would attract them by blogging about building AI-powered investment products. Here I am, blogging about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Did the Memos Say?
&lt;/h2&gt;

&lt;p&gt;About half an hour after those documents were committed, Claude Fable 5.1, running in Claude Code, worked through the evaluation against the index, the issues and pull requests it pointed to, and its own web research on competitors and regulation. The next morning, Cursor’s agent, Composer, did the same evaluation independently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faybq9yn1ukq6jwzlo1sr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faybq9yn1ukq6jwzlo1sr.png" alt="Flow chart, top to bottom. September 17: an index of the whole record, abandoned experiments included, and five gates, each with its failure condition written first. September 17 to 18: Claude Fable 5.1 in Claude Code and Composer in Cursor each write a memo. Both say personal only. September 20: Claude Opus reviews both memos and finds the same two mistakes in each. September 20 to October 10: 25 arguments tried, each written down. Verdict unchanged." width="800" height="840"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;How the evaluation ran, from the record to the verdict. Dates are 2026.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Both came back with the same verdict: “personal only.” Keep running the system on my own money, and don’t turn it into a company. The first memo spelled it out: don’t found one now, and don’t raise money. It summed up the honest pitch as “concentrated, high-turnover S&amp;amp;P exposure with ML attached, viable only inside an IRA,” which is very close to the failure condition I’d written for the first gate. It also recommended that I start the job search right away, rather than waiting for my two-year mark.&lt;/p&gt;

&lt;p&gt;That phrase “viable only inside an IRA” needs some context. My system rebalances roughly once a month, which means it sells stocks it has held for less than a year. In an ordinary brokerage account, those profits are short-term capital gains, which in the US are taxed at the same rate as income, every year, and that tax drag erases a lot of the advantage of trading actively. In a retirement account like an IRA, trades aren’t taxed as they happen, so that drag disappears. So, any product built on my system would have had to be sold into retirement accounts.&lt;/p&gt;

&lt;p&gt;I was heartbroken. I was 21 months in, and I felt close to something big. The answer was that launching a financial product on what I had wasn’t justified.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can Two AI Models Be Wrong in the Same Way?
&lt;/h2&gt;

&lt;p&gt;Yes, and that was the first thing I learned once I started pushing back.&lt;/p&gt;

&lt;p&gt;On September 20, I had Claude Opus review both memos. It found the same two mistakes in each. The first was that both memos described the strategy as riskier than the version I actually run, calling it levered or high-beta when it moves with the market about one for one.&lt;/p&gt;

&lt;p&gt;The second mistake was about those retirement accounts. Both memos said they were small by nature, because the government caps how much you can contribute to an IRA each year. That’s true for new contributions, but it misses rollover IRAs. When people leave a job, they often move their whole 401(k), i.e., their workplace retirement savings, into an IRA, and a rollover isn’t subject to the yearly cap. So, the accounts the product would have been sold into could be much larger than the memos assumed. The correction added to both memos says so plainly.&lt;/p&gt;

&lt;p&gt;Neither mistake changed the verdict. But they changed how I read the agreement. Two models that read the same index and the same prompt are not two independent opinions. They share the blind spots of the record they were given, and, as the IRA mistake showed, they can also share a wrong assumption about the world that wasn’t in the record at all. Agreement between them is worth something, just much less than it feels like when you first read it.&lt;/p&gt;

&lt;p&gt;So, I did with the memos what I’d started doing with my research: I reviewed them again with a different model, and I kept going until the review stopped finding anything major.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Many Ways Can You Argue With a Verdict?
&lt;/h2&gt;

&lt;p&gt;I didn’t accept it. I spent days trying to poke holes in it, and every time I thought of a reason the memos might be wrong, I had it investigated. I didn’t sit down with a list of counterarguments. Each one was a follow-up thought I had while I was digesting the idea that there wasn’t going to be a company.&lt;/p&gt;

&lt;p&gt;Each one also got written down, in a section of the memo called “Arguments tried and retired,” with a rule at the top: “A new argument should say which of these it is not.” In other words, before I could spend another afternoon on an idea, I had to check that I hadn’t already lost that argument once.&lt;/p&gt;

&lt;p&gt;By October 10, there were 25 entries. Here are a few of them, so you get a feel for it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sell to financial advisers instead of to individual investors. It would fix the cost of finding customers one at a time, but professional buyers screen on exactly the long, audited track record that I didn’t have, so it raises the bar instead of lowering it.&lt;/li&gt;
&lt;li&gt;Charge only a performance fee, i.e., a share of the profits instead of a flat fee. US rules generally allow performance fees only for clients who are already wealthy, which excludes the very customers every other idea targeted.&lt;/li&gt;
&lt;li&gt;Wrap the strategy in an actively managed ETF, an exchange-traded fund that trades on the stock market like a single stock, to solve the tax problem. ETFs can avoid passing capital gains on to their investors through in-kind redemptions: when a large investor cashes out, the fund hands over shares of the stocks it holds rather than selling them for cash, so the gains are never realized inside the fund. The structure works, and it’s how established funds avoid distributing gains, but it costs hundreds of thousands of dollars a year to run, so it only makes sense for a fund that’s already large.&lt;/li&gt;
&lt;li&gt;Registering as an adviser turned out to be much cheaper than the memos assumed, if I did the paperwork myself. That was true, and it was kept as a correction, but cheaper registration doesn’t create any evidence that the strategy is better than an index fund.&lt;/li&gt;
&lt;li&gt;Instead of waiting years for the evidence, change the portfolio so that the evidence arrives sooner. Holding more stocks would make the portfolio swing less relative to the market, and with less noise, a real edge would show up in fewer years. The arithmetic worked, but the data didn’t cooperate: the model’s picks only stood out at the very top of its list, so adding more stocks diluted the edge as fast as it cut the noise.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwh6p2wje3h3cxs2mfe9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwh6p2wje3h3cxs2mfe9g.png" alt="A five-by-five grid of 25 cards, one per argument, in the order raised. Sixteen gray cards were retired, six blue cards were kept in part, such as rollover IRAs not being capped and registering as an adviser myself, and three amber cards are still open, including whether it is software rather than advice and having the customer approve each trade." width="800" height="760"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;All 25 arguments from the memo, in the order I raised them. The blue ones fixed something the memos had gotten wrong; none of them changed the verdict.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A handful were kept in part, because they fixed something the memos had gotten wrong. A few are still open, including two that only a securities lawyer can answer. None of them moved the verdict.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happened on the Day the Verdict Almost Flipped?
&lt;/h2&gt;

&lt;p&gt;On September 22, I ran an evidence review that went my way, four times in a row. Each of the four was a correction, and each one made the project look better than the memos had said. One of them confirmed that my execution costs, i.e., what I lose between deciding to trade and actually getting filled at the broker, were essentially zero, which is a measurement I’d spent months building the tooling to make.&lt;/p&gt;

&lt;p&gt;The pull request I opened that day was drafted to change the verdict from “personal only” to “90-day discovery,” i.e., go and find out whether real customers would pay. Then I checked the biggest of the four results on a second, longer set of price history. The first set covered about 8 years and the second about 24. On the 24 years, the result didn’t hold. It was the second favorable result in three days to fail on the longer history. The pull request that merged says, near the top, “This PR was originally drafted as a revision to &lt;code&gt;90-DAY DISCOVERY&lt;/code&gt; on the eight-year evidence. Checking the 24-year pool reversed it.”&lt;/p&gt;

&lt;p&gt;If you haven’t spent time with market data, this pattern is worth knowing about, because it’s the rule rather than the exception. Over a few years, it’s surprisingly easy to find a way of picking stocks that beats the market, partly because there are so many ways to try and some of them will win by chance. Over longer periods, most of those advantages shrink or disappear. One well-known study, by David McLean and Jeffrey Pontiff in the &lt;em&gt;Journal of Finance&lt;/em&gt; in 2016, looked at 97 stock-market patterns that academic papers had found to predict returns. After the papers were published, the patterns earned, on average, 58% less than they had in the original research.&lt;/p&gt;

&lt;p&gt;It was incredibly disappointing. As an entrepreneur, it’s very exciting when you feel like you’ve discovered something significant, and when it turns out not to be significant, it’s hard to come down from that high. Higher highs and lower lows are the life of an entrepreneur.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, What Actually Decides It?
&lt;/h2&gt;

&lt;p&gt;Looking back at all 25 arguments, the pattern is simple. Packaging, pricing, partners and the sales channel can all change the business questions. Only time, with real money and results that can’t be revised after the fact, changes the evidence question, and nothing I could build or buy makes that time pass faster.&lt;/p&gt;

&lt;p&gt;The reason it takes so long comes down to signal and noise. If a strategy’s average advantage is small compared with how much its results swing from year to year, then a few good years look the same as a few lucky ones. At the size of advantage on offer here, and with how much a concentrated portfolio, one that holds relatively few stocks, swings around the market, telling skill from luck with live money would take decades, not quarters. That’s the same wall the momentum index in my last post hit, even after I reconstructed 24 years of its history.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6yhp9bwpg3lds2b0jemz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6yhp9bwpg3lds2b0jemz.png" alt="A curve falling from upper left to lower right on a log scale: the years of results needed before an edge is twice its own noise, against how big the edge is compared with how much it swings around the index. A ratio of 1 needs 4 years, 0.5 needs 16 and 0.25 needs 64. A dashed red line at 2 years marks about how long I have traded live." width="800" height="560"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The textbook arithmetic, not my system’s numbers: the smaller the edge compared with its swings, the more years it takes before luck can be ruled out.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;My system has now run continuously on live capital for almost two years, and on the evidence so far, its results are not statistically distinguishable from cheaper alternatives. In other words, the difference is too small, compared with the noise, to rule out luck. Even the most celebrated stock pickers go through long stretches of trailing the index. A non-professional launching a financial product on that evidence just didn’t hold up.&lt;/p&gt;

&lt;p&gt;Somewhere in the middle of the arguing, after the first memo was drafted, I read Burton Malkiel’s &lt;em&gt;A Random Walk Down Wall Street&lt;/em&gt;. I’d read a lot of finance books, but never this one. Malkiel’s argument, first published in 1973 and updated through many editions since, is that markets absorb new information so quickly that consistently beating them is extremely hard, so that an investor who buys and holds a low-cost, diversified index fund is likely to do better than most portfolios carefully picked by professionals. I generally knew that broad index funds are near impossible to beat, but hearing it laid out with that much research behind it was very helpful. I felt like I’d spent nearly two years proving the thesis of the book!&lt;/p&gt;

&lt;h2&gt;
  
  
  Was It 21 Months Wasted?
&lt;/h2&gt;

&lt;p&gt;Some people will read this as 21 months spent proving a negative. I don’t regret it. I went deep on the principles behind quantitative trading: finding and storing data you can trust, building machine-learning pipelines that are both fast and reliable, and building execution that’s fast and reliable with real money on the line. I learned a ton. That being said, I do wish the outcome had been different.&lt;/p&gt;

&lt;p&gt;It’s always better if you can validate an idea up front, so that you don’t spend more time than you need to chasing something that won’t work. The kill criterion and the gates were my attempt at that. But I also don’t think I could have been confident either way without doing the work. Sometimes failing along the way, and the hindsight that comes with it, is the only way to know.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happens Now?
&lt;/h2&gt;

&lt;p&gt;I stopped building toward a company. The system keeps running on my own accounts, and I still do research on the side in between other things. The evidence question stays open, and if it’s ever answered, it will be answered by time rather than by another memo.&lt;/p&gt;

&lt;p&gt;Next, I’m going back to leading engineering teams, and I’m taking with me the habits that made this decision possible: writing the gates before looking at the result, holding my own ideas to the same evidence bar I’d hold anyone else’s, and treating a pre-committed stop as something to carry out rather than renegotiate.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This describes software I run on my own accounts. It is not investment advice and I do not offer investment services.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>fintech</category>
      <category>startup</category>
    </item>
    <item>
      <title>Changing only the random seed made my trading model look twice as good</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Mon, 12 Oct 2026 21:27:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/changing-only-the-random-seed-made-my-trading-model-look-twice-as-good-406</link>
      <guid>https://dev.to/redgeoff/changing-only-the-random-seed-made-my-trading-model-look-twice-as-good-406</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0xaz7x1idneklafu9hx9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0xaz7x1idneklafu9hx9.jpg" alt="Eleven thin gray lines wandering right from a single bright starting point on a dark background, spreading apart as they go, with one glowing red line among them ending highest" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: author, drawn with code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is a story about how I found out that most of the decisions in one of my research logs were coin flips, and about what I changed so that it wouldn’t happen again.&lt;/p&gt;

&lt;p&gt;In September 2026, I ran the same research model eleven times. The code, the data and the settings were identical each time, and the only thing I changed was the random seed. The best of those eleven runs scored about twice as well as the worst.&lt;/p&gt;

&lt;p&gt;That would just be a curiosity if I hadn’t spent months making decisions by comparing a single run against a single other run. When we went back through the research log for that model, 14 of the 21 decisions it recorded, mostly about whether to keep a feature or throw it out, rested on a difference smaller than what the seed alone could produce.&lt;/p&gt;

&lt;p&gt;If you’re new to this, here’s a bit of background. I build models that pick stocks, and I can’t test one by waiting ten years to see how it does. So, I backtest it: I replay history, let the model make its picks as if it were living through each date, and score those picks against what actually happened next. I also run hyperparameter searches, which backtest hundreds or thousands of versions of a model with different settings and compare them. Over the last couple of years, that has added up to a lot of models.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://redgeoff.com/posts/trading-model-leakage/" rel="noopener noreferrer"&gt;my last post&lt;/a&gt;, I wrote about leakage, where information from the future sneaks into the replay and makes a backtest look better than anything you could have done for real. This post is about two other ways of fooling yourself: noise, and the choices you make as the researcher. They’re harder to catch, because neither of them is a bug in the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Did This Start?
&lt;/h2&gt;

&lt;p&gt;It started with a rerun. Earlier in 2026, I had measured what my live trades actually cost to execute, and the answer was close to nothing. That made me wonder whether a few research lines that I had already closed deserved a second look, since some of them had been judged with a cost assumption that was now clearly too pessimistic. So, an agent reran some of the old experiments.&lt;/p&gt;

&lt;p&gt;When I reviewed the agent’s work, the conclusions held up, but several of the supporting numbers were wrong. Fixing those meant actually running a check that had been skipped, and that check reran a configuration from the old log with the identical command. The log had recorded it as a solid result. The rerun came back negative.&lt;/p&gt;

&lt;p&gt;The first question was whether the engine was random at all, and it wasn’t. Two runs with the same seed on the same machine produced results that were identical down to the byte. So, whatever had changed between the original run and the rerun, it wasn’t chance, and the data changes since then became their own investigation.&lt;/p&gt;

&lt;p&gt;However, it raised a question that I had never asked. If the engine gives the same answer every time for a given seed, how much does the answer move when the seed changes?&lt;/p&gt;

&lt;h2&gt;
  
  
  How Much Does a Result Move When Nothing Changes?
&lt;/h2&gt;

&lt;p&gt;First, a little background on why a seed matters at all. The models in that research line were gradient-boosted trees, and like a lot of tree models, each tree is trained on a random subset of the features and a random subset of the rows. The seed decides which subsets. If you change it, you get a different set of trees from the same data, which is supposed to be a detail.&lt;/p&gt;

&lt;p&gt;On September 8, 2026, Claude and I held one configuration fixed and ran it with eleven different seeds over the full four-year research window. The best seed scored about twice as well as the worst. From that spread, you can work out the smallest difference between two single runs that you can trust, i.e. a difference that you’d only expect to see by chance about one time in twenty.&lt;/p&gt;

&lt;p&gt;Then we went back through the log. It recorded 21 decisions that had been made by comparing one run against one other run, and 14 of them rested on a smaller difference than that. Some were features I had thrown out as harmful, and four were features I had kept because they seemed to help. In other words, the evidence on file couldn’t tell any of those 14 variants apart from the run they were compared against, in either direction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7gz87dc9dxb1vaqorcy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7gz87dc9dxb1vaqorcy9.png" alt="Horizontal bar chart of 21 keep-or-drop decisions from a research log, sorted by the size of the difference each rested on, as a multiple of what changing the random seed alone can produce. A red line marks 1x. Fourteen bars, including four decisions to keep a feature, end left of the line, inside the noise; seven extend past it." width="800" height="640"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Each bar is one of the 21 keep-or-drop decisions in the research log, measured by the difference it rested on, as a multiple of what the random seed alone can produce. Fourteen fall short of the line.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One of those four soon confirmed it. A later rerun, done properly this time with the same seed on both sides, found that a feature the log had recorded as helping was actually hurting. That’s exactly what you’d expect from a difference inside the noise, since it can come out either way.&lt;/p&gt;

&lt;p&gt;Fortunately, none of those features were in production, so nothing needed reverting. But the same habit of comparing one run against one other run was also in my more active research lines. When we measured the noise for the daily research engine the same way, one recorded decision stood out. In a long/short research line, which buys some stocks and bets against others by shorting them, the time of day to trade had been chosen on a difference between 17 and 29 times smaller than that engine’s noise. In other words, the backtest couldn’t separate the candidate times at all. The same measurement also showed that the worst loss from peak to trough was even more sensitive to the seed than the score was, and more than doubled between the gentlest seed and the harshest.&lt;/p&gt;

&lt;p&gt;So, when does my live system trade? Shortly after the open rather than at the opening bell, and I’d defend that without any backtest. The first stretch after the market opens is the most volatile part of the day, which makes it hard to hit a price target or to model the price you’ll actually get. That reasoning is about how the market works, and no seed can flip it.&lt;/p&gt;

&lt;p&gt;The rules that came out of all this are short:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No feature is declared harmful, or kept, on a difference smaller than the measured noise.&lt;/li&gt;
&lt;li&gt;Comparisons either use the same seed on both sides, or run several seeds per side and compare the averages.&lt;/li&gt;
&lt;li&gt;The seed, the number of threads and where the data came from are stamped into every recorded result, so that any number in the log can be reproduced.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There was one more surprise in the details. The library we were using doesn’t pick a random seed when you don’t give it one. It uses fixed defaults, so every “unseeded” run in the log had been perfectly reproducible all along, and had been sitting on one arbitrary draw that nobody had recorded or varied. Moreover, setting the seed to 0 doesn’t reproduce those runs, because it overrides the defaults with different values. The agent had assumed that it would, and there’s now a test that pins the fact that it doesn’t.&lt;/p&gt;

&lt;p&gt;This was tough to learn, as it had taken me a lot of time to engineer myself into those conclusions. Once the coin flips came to light, I kept pushing to see if there was a way to improve the statistical significance of my results. That question, how long it takes before you can tell a real edge from luck, runs through the rest of this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can I Rebuild an Index Fund From Scratch?
&lt;/h2&gt;

&lt;p&gt;A couple of weeks later, I wanted a fair comparison for my own model: something cheap and simple that I could hold it up against, over long stretches of history that included real bear markets. The obvious candidate was a public momentum index fund, which holds the stocks that have risen the most over the past year. It’s one of the cheapest and best-known ways to buy a simple stock-picking rule, which makes it a fair bar for any model that picks stocks. The problem was that the fund only goes back to 2015, and its index’s history before that is the index provider’s own backtest.&lt;/p&gt;

&lt;p&gt;So, the plan was to rebuild the index from its published rules, using my own data, and run it back through history myself.&lt;/p&gt;

&lt;p&gt;The catch is that a rebuilt index involves a lot of choices, e.g. how far back to measure momentum, how to size each position and when to rebalance (reshuffle the portfolio), and every one of them is a knob. If I build the benchmark, look at how my model compares, and then adjust the benchmark, I’ve tuned my own yardstick.&lt;/p&gt;

&lt;p&gt;To avoid that, the spec was written first and merged before any construction code existed. It included a gate that the rebuild had to pass over the years where the real fund exists: its annual return had to land within three percentage points of the fund’s, its risk-adjusted return (how much it earned for how bumpy the ride was) had to be within a fixed margin, and its returns had to move with the fund’s, period by period, with a correlation of at least 0.8, where 1 means moving in lockstep. All three had to pass or the rebuild was disqualified. The spec even explains why it was written first: every parameter is a researcher degree of freedom, and my research log already had four results on record that had been retracted after a closer look.&lt;/p&gt;

&lt;p&gt;Writing the gate first wasn’t a new habit for me. When working with LLMs, I’ve found that you have to have very clear acceptance criteria, especially if you want an agent to run unsupervised for long periods of time. I set the initial rules and then refined them with the models.&lt;/p&gt;

&lt;p&gt;There was one more guard. The benchmark was deliberately not registered as one of my models, as registered models can be fed into the hyperparameter search. Otherwise, someone, or more likely an agent, could have swept the benchmark’s own parameters and kept the best-scoring version. Changing it requires editing the code, which shows up in the history.&lt;/p&gt;

&lt;p&gt;On September 23, 2026, the first build failed the gate by a wide margin. The leading suspect was that it weighted every stock equally, while the real index weights by company size. So, the second build pulled historical share counts from EDGAR, the SEC’s filing database, and weighted by size. That closed about a tenth of the gap, and it failed again.&lt;/p&gt;

&lt;p&gt;That second failure was actually useful. A pass would have justified buying a commercial dataset to reach further back in time, but closing only a tenth of the gap meant that better share counts weren’t the problem. So, I found out that the data wasn’t worth buying without having to buy it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Was That Moving the Goalposts?
&lt;/h2&gt;

&lt;p&gt;This is the part I’ve thought the hardest about how to tell honestly, because the spec said that if the gate failed, the work stopped. It failed twice, and I didn’t stop.&lt;/p&gt;

&lt;p&gt;What changed was the diagnosis. The benchmark had been built to rebalance on my model’s dates, roughly once a month, so that a comparison between the two would only differ in how they picked stocks. Meanwhile, the gate asked it to track a fund that rebalances twice a year. Those two requirements contradict each other, so the gate was close to impossible to pass by construction, and both failures had to be read in that light.&lt;/p&gt;

&lt;p&gt;So, the work split into two builds with different jobs. The first is a faithful replica on the fund’s own twice-a-year schedule, and its only purpose is to pass the gate and prove that the index can be recreated from my data at all. The second is the monthly build that my model gets compared against, which is then justified by the replica passing. The thresholds never moved, and each new attempt was written up as its own issue, with the reason it might close the gap, before it was run.&lt;/p&gt;

&lt;p&gt;On the fund’s own schedule alone, the replica still failed. Then it was weighted by the shares available to public investors (the free float, which is what the index uses), rather than every share a company has issued, and it passed. That happened in the third pull request of the day, about an hour and a quarter after the first failure was merged.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd6gvege9ce191eymjjte.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd6gvege9ce191eymjjte.png" alt="Bar chart of the gap in annual return between the rebuilt index and the real fund over six steps: 7.41 and 6.66 percentage points on my model's monthly dates, then 5.42 on the fund's own schedule, all above a dashed limit of 3 set before the first build; then 1.93 with free-float weights, 1.50 with the reference-date lag and daily volatility found from the fund's holdings, and 0.86 with the provider's published weight caps and buffer rule, all below it." width="800" height="540"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The gap between the rebuilt index and the real fund’s annual return, step by step, against the pre-registered limit of three percentage points. The first two were scored on my model’s monthly schedule, the rest on the fund’s.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That being said, I don’t think “the thresholds never moved” settles it. A gate that you’re allowed to keep attempting is a search of its own, and with enough attempts, something will eventually pass. What convinced me that this one hadn’t just been searched into passing was the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  What If You Fit to Holdings Instead of Returns?
&lt;/h2&gt;

&lt;p&gt;A replica that matches the fund’s return could still be holding the wrong stocks, as lots of different portfolios produce similar returns over a few years, especially when they’re all tilted the same way. However, the fund has to file its actual holdings with the SEC, so there’s a much harder target available: the list of roughly 100 companies it held at each rebalance, and how much of each it held.&lt;/p&gt;

&lt;p&gt;So, with the gate already passed, Claude compared the replica against those filings. The first result said that where the replica held the same company as the fund, it sized it almost exactly right, but about a third of the companies were different.&lt;/p&gt;

&lt;p&gt;Two bugs in the comparison itself came out along the way. It had been pitting a freshly rebalanced replica against holdings from months after the fund’s last rebalance, and the code that matched company names to tickers had been quietly dropping as much as a third of the fund’s holdings. For example, a check for " CO" ate the “Cos.” in “Marsh &amp;amp; McLennan Cos., Inc.,” which then matched nothing. After both fixes, the replica still disagreed with the fund on about a third of the companies, so the difference was real and it was in how the replica ranked stocks.&lt;/p&gt;

&lt;p&gt;Part of that ranking was still a guess, and the agent couldn’t read the index provider’s methodology document, because the provider’s site blocked automated downloads. So, it swept the uncertain parameters and scored each setting by how many of the fund’s actual holdings the replica matched, never by return.&lt;/p&gt;

&lt;p&gt;One sweep found that the index measures momentum about 42 trading days before each rebalance, rather than on the rebalance date itself. That moved the share of matching companies from about two thirds to about 80%, and it did better on the filings that were held out of the sweep, which it never saw while choosing, than on the ones it was fitted to.&lt;/p&gt;

&lt;p&gt;Another sweep, over how many weeks of volatility (how much a stock’s price swings) to measure, came back flat across a tenfold range. That turned out to be the clue, as the form was wrong rather than the length. A line in the fund’s own documentation described volatility as measured on daily returns, not weekly, and on the holdings, one year of daily returns beat the old assumption on the held-out filings. A shorter window won on the filings it was fitted to and lost on the held-out ones, which is what overfitting looks like: a setting that fits the quirks of the data it was tuned on rather than the real pattern. So, the agent took the round one-year value instead.&lt;/p&gt;

&lt;p&gt;Neither change was chosen by the gate, and the commit messages say so when the gate didn’t cooperate. The lag narrowed the return gap, while two of the gate’s other measures got slightly worse. Switching to daily volatility didn’t move the return gap at all, and it was adopted on the strength of the documentation and the held-out holdings.&lt;/p&gt;

&lt;p&gt;Then I downloaded the methodology document by hand, and its appendix confirmed both. Volatility is the “standard deviation of daily price returns,” and momentum is measured between month-ends ending two months before the rebalance, which from a late-March rebalance is about 42 trading days. That’s exactly the lag the sweep had found! The document also corrected a couple of things we had guessed wrong, including the cap on how much any one company can weigh and the order of the rules for keeping existing holdings, and those brought the gap down to under one percentage point.&lt;/p&gt;

&lt;p&gt;I think this is the most useful thing I took from the whole exercise. Fitting the same parameters to returns would have picked a volatility window that, measured against the holdings, didn’t matter at all, and I would have declared the spec identified. On the other hand, matching about 100 specific companies across 13 real rebalances isn’t something that a single free parameter does by luck. So, if you’re validating a model or a reconstruction, look for the target that is hardest to hit by accident, and fit to that.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Gate Was Green, but Were the Numbers Right?
&lt;/h2&gt;

&lt;p&gt;The replica still only started in 2011, because the free source of company sizes it used begins around then. To reach back further, Claude and I used the same trick as in my last post. An S&amp;amp;P 500 index fund holds every company in the index in proportion to its size, and it has filed those holdings with the SEC going back to 1995. So, the value of each holding in those filings tells you the company’s size on that date.&lt;/p&gt;

&lt;p&gt;The longer replica passed the gate again on the years where the real fund exists, with about 81% of its companies in common with the fund and an average weight error of 0.13 percentage points against the fund’s own filings.&lt;/p&gt;

&lt;p&gt;Then I reviewed it, and the review still found three wrong numbers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The daily return series silently dropped one real day of returns in every rebalance period. After the fix, it agreed with the period-by-period returns, and a regression test now pins that.&lt;/li&gt;
&lt;li&gt;For a company that joined the index between two filings, a fallback took its size from the next filing. That’s leakage, since it uses a filing nobody could have seen yet, which is my last post in a single sentence. The effect was small, but the default is now strictly point-in-time, i.e. it only uses what was known on each date.&lt;/li&gt;
&lt;li&gt;Prices jumped at the point where one data vendor’s history hands over to another’s, so the long runs were redone on a single source, and the seam is filed as its own bug, which is still open.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The way I do these reviews isn’t sophisticated. On delicate or complex work, I ask a model to go through the result and find what’s wrong, often switching to a different model from the one that did the work, and I repeat this until the review stops finding anything major. All three of these turned up after every check had already passed.&lt;/p&gt;

&lt;p&gt;Two more findings from that review were about noise rather than bugs. The first was that leaving out the companies that later failed, the survivorship bias from my last post, flattered the result by a measurable amount. It flattered it the most during the dot-com bust, because the missing companies were the ones that collapsed. The second was that shifting every rebalance date by a single week, earlier or later, moved the result about as much as fixing the survivorship bias had. Nobody chooses the calendar date their backtest happens to rebalance on, yet it moved the answer as much as a real data fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, Could It Tell Itself From Luck?
&lt;/h2&gt;

&lt;p&gt;No. After all of that, with a gate written in advance, passed on returns, checked against holdings and reviewed until the review went quiet, the reconstruction gave me 24 years of a momentum index, most of them from before the fund existed. Over those 24 years, its edge over the plain S&amp;amp;P 500 isn’t statistically established, meaning that it isn’t large enough, compared with the noise, to rule out luck.&lt;/p&gt;

&lt;p&gt;The reconstruction did what it was built to do. When the edge you’re measuring is small and markets are noisy, telling skill from luck takes decades, not quarters, and even 24 years can fall short. My own model runs into the same wall: on the evidence so far, it isn’t statistically distinguishable from cheaper alternatives. What I decided to do about that is the subject of my next post.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I’d Do From Day One
&lt;/h2&gt;

&lt;p&gt;If I were starting a research project like this again, this is the list I’d hand to myself and to every agent working with me:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Measure the noise before the first comparison. Run one configuration across several seeds and work out the smallest difference you can trust.&lt;/li&gt;
&lt;li&gt;Write the gate before the build. Freeze the spec and the pass/fail criteria first, with the reason for each, and make the thing you’re testing hard to tune by accident.&lt;/li&gt;
&lt;li&gt;Never widen a threshold. If the gate itself turns out to be wrong, say so in writing, split the job and keep the threshold.&lt;/li&gt;
&lt;li&gt;Fit to the hardest target you can find, e.g. holdings rather than returns.&lt;/li&gt;
&lt;li&gt;Review the work again after the gate passes, with a different model if you can, until the review stops finding things.&lt;/li&gt;
&lt;li&gt;Shift your dates. If moving the calendar by a week moves the answer, the answer is smaller than it looks.&lt;/li&gt;
&lt;li&gt;Keep the graveyard. Every closed experiment stays in the repo with the gate it was judged against and its verdict, so that the next person, or the next agent, can see what was already tried and why it failed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This describes software I run on my own accounts. It is not investment advice and I do not offer investment services.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>data</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>My first trading models knew which companies would survive</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Mon, 05 Oct 2026 22:38:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/my-first-trading-models-knew-which-companies-would-survive-30lk</link>
      <guid>https://dev.to/redgeoff/my-first-trading-models-knew-which-companies-would-survive-30lk</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzw1sew2qnudt44sp3p3i.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzw1sew2qnudt44sp3p3i.jpg" alt="Rows of grey gravestones receding into fog under a dusk sky, with a single bright red line chart climbing through them from lower left to upper right" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: author, drawn with code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;My first live trading bot started trading real money on December 2, 2024. The models behind it had been trained on years of stock-market history, and every company in that history had something in common: it was in the S&amp;amp;P 500 on the day I trained the model.&lt;/p&gt;

&lt;p&gt;That sounds harmless until you think about what it leaves out. A company that was in the index in 2016 and went bankrupt in 2019 wasn’t in the training data at all, and a company that joined the index in 2025 was in it all the way back. In other words, the models learned from a version of the market where nothing ever failed and every stock was already a future winner.&lt;/p&gt;

&lt;p&gt;That was a leak, and it went live. It wasn’t the only one either.&lt;/p&gt;

&lt;p&gt;If you haven’t built one of these systems, here’s what I mean by a leak. You can’t test a trading model by waiting ten years to see how it does, so instead you backtest it: replay history, let the model pick stocks as if it were living through each date, and score those picks against what actually happened next. A leak is any information that sneaks into that replay which the model couldn’t have had on the date in question. It doesn’t have to be anything as obvious as tomorrow’s price. Knowing which companies will still be around in five years is enough, and the result is a backtest that looks better than anything you could have done for real.&lt;/p&gt;

&lt;p&gt;The standard defence is to train walk-forward. For each rebalancing date (the days the portfolio is reshuffled, roughly monthly for me), the model trains only on data from before that date, picks its stocks, holds them until the next rebalancing date, and then the whole thing steps forward and repeats. That way, no single model is ever scored on data it was trained on. Walk-forward is necessary, but as you’ll see, every leak in this post got through it, because each one smuggled the future in somewhere other than the training dates: the list of stocks, the shape of the data, or the data itself, through prices adjusted the wrong way or figures dated before anyone could have known them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp07elutkrs6lhx1g2h63.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp07elutkrs6lhx1g2h63.png" alt="Diagram of walk-forward training: four steps, each training on the past, picking on the rebalancing date and holding until the next one, moving forward in time. Below it, the three ways the leaks in this post got past walk-forward: the list of stocks (survivorship), the shape of the data (columns and rows decided by the whole run), and the data itself (prices adjusted the wrong way, or figures dated before anyone could know them). At the bottom, the check that catches the second: training step by step must give bit-for-bit the same picks as training all at once." width="800" height="940"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, this post is about the leaks I shipped, the ones I caught in research before they shipped, and the times an AI was sure it had found a leak and was wrong. Every one of them is a reason that backtests are hard to trust, including your own. Along the way I’ve ended up with one rule for all three: you can’t reason your way to the answer. You need a test that makes a leak show up as a number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Survivors
&lt;/h2&gt;

&lt;p&gt;What gave it away was a backtest that was too good. I tune the model by running hyperparameter searches, where I backtest hundreds of versions of the model with different settings and compare them. In August 2025, one of those runs came back with a 2020 that was simply impossible, and most of that year’s profit came from a single holding. When I went to look it up, neither Yahoo Finance nor Google Finance had any prices for its ticker before 2021, and my note from the investigation reads: “Perhaps the symbol was renamed?”&lt;/p&gt;

&lt;p&gt;It had been. It was Chesapeake Energy, which had been dropped from the S&amp;amp;P 500 in 2018, did a 1-for-200 reverse split in April 2020, went bankrupt later that year, and eventually merged, took on a new name and rejoined the index in 2025. My backtest was holding it in 2020, two years after it had left the index, because the training code only knew about the index as it stood today. (Keep that reverse split in mind, as it shows up again later in this post.)&lt;/p&gt;

&lt;p&gt;Fixing survivorship bias turned out to be mostly a data problem. First, I needed the S&amp;amp;P 500’s membership for every day of the training period, not just the current list. I built this from the public record of index changes and had a couple of AI models double-check the list. Then I needed price history for the companies that had left the index, many of which no longer trade. Finally, the training loop had to resolve the set of stocks it was allowed to pick from (its universe) date by date, so that a model trained on 2016 data only ever saw companies that were actually in the index in 2016.&lt;/p&gt;

&lt;p&gt;When the fix first ran, the backtest fell apart. The note I left myself in the pull request was, in all caps, “THE ANNUALIZED RETURN IS NEAR 0!!!” That’s what removing a leak is supposed to do, and it’s a very unpleasant thing to watch.&lt;/p&gt;

&lt;p&gt;The fix reached the production training path in late September 2025, about ten months after the first live trade.&lt;/p&gt;

&lt;p&gt;There was one experiment from that period that I’m still glad I ran. I wondered whether a small, controlled leak might be acceptable: train the first stretch of the model on a later snapshot of the index, so that it learned from today’s large companies, and then walk forward point-in-time from there. It gave no reliable improvement. My conclusion at the time was that a model trained on a fixed list of companies never sees a stock enter or leave the index, which leaves it less prepared for the real index, where that happens all the time.&lt;/p&gt;

&lt;p&gt;Unfortunately, that wasn’t the end of it. A year later, in October 2026, a copy of the equal-weight S&amp;amp;P 500 that an agent and I had rebuilt from my research data beat the real equal-weight index fund by a margin that a copy has no business beating it by. The two moved almost in lockstep, so the copy was tracking the right thing, but it was consistently doing better. That’s the same “too good” signature, and it turned out to be survivorship again, coming from two places.&lt;/p&gt;

&lt;p&gt;The first was the membership list itself. The public record of index changes I’d built it from is sparse before about 2007, so the early lists were short and slightly wrong. To check, we rebuilt membership from the holdings of an S&amp;amp;P 500 index fund, which has to file its complete list of holdings with the SEC. Against those filings, my list was 74 companies short in 2001 and still 5 short in 2009, and it even contained a few companies that hadn’t gone public yet. The AI models I’d asked to double-check the list in 2025 hadn’t caught any of this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo37k80jkfkyqldkq9jws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo37k80jkfkyqldkq9jws.png" alt="Line chart from 1995 to 2026 of how many S&amp;amp;P 500 companies my list held on each date SPY filed its holdings with the SEC. SPY's count sits near 500 throughout. My list starts at 379 in 1995, 121 short, is 74 short in 2001 and 5 short in 2009, and matches from 2010." width="800" height="540"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;How many S&amp;amp;P 500 members my list knew about, against the holdings SPY filed with the SEC. The gap is the least my 2025 fix still left out, since the list also held a few companies that hadn’t gone public yet.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The second was prices. Many of the companies that failed outright, like Lehman Brothers, Bear Stearns, Enron and WorldCom, have no price data in either of my data sources, so even with a correct list they can never be picked or held in a backtest.&lt;/p&gt;

&lt;p&gt;This one mostly affects my long-history research backtests rather than the live system, since the data the live configuration was chosen from covers 99.6% of index members. But it means that for my backtests before about 2016, the honest reading is “probably an upper bound”, and fixing it properly needs a data source that still sells prices for companies that no longer exist.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, What Did It Cost?
&lt;/h2&gt;

&lt;p&gt;I don’t know, and I think the reason is worth explaining.&lt;/p&gt;

&lt;p&gt;First, a correction to the intuition. A live model can’t see the future, because on the day it makes a prediction there’s no future data to see. Today’s S&amp;amp;P 500 list is the correct list for today. So, the live models were never peeking at tomorrow’s prices. The damage was in two other places:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The backtests I used to choose the model and its settings were inflated by the leak, so the configuration that went live was selected on a flattering number.&lt;/li&gt;
&lt;li&gt;The live model had been trained on a history with no failures in it, so whatever it had learned, it had learned from survivors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Putting a price on that requires comparing what the model expected with what the account actually did, period by period, and in 2025 I had no mechanism for tracking that gap. Moreover, the model worked from end-of-day closing prices while the orders filled the next morning, so any gap I computed mixed model error with hours of ordinary market movement.&lt;/p&gt;

&lt;p&gt;That was a consequence of how the early system worked. It ran at a fairly leisurely pace after the market closed: download the day’s prices, retrain the model, decide what to buy and sell, and queue the orders for the next morning. Since then, a lot of optimization and engineering has gone into doing all of that during the trading day. The system pulls a price snapshot at a fixed time in the morning, trains the model on it and starts trading, with a median of about 12 minutes from the snapshot to the first fill. For bots that run this way, the model’s prices and the fill prices are now minutes apart instead of a night apart.&lt;/p&gt;

&lt;p&gt;There are also now reports that split a bot’s live result into what the model predicted, what the portfolio’s composition delivered and what execution cost. When I finally ran those reports across the live history in September 2026, every period I analyzed had run without a fixed price time, so the execution numbers came with a caveat that they couldn’t really be read as execution at all. The measurement that would have priced the leak simply didn’t exist yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Leak the LLMs Couldn’t Find
&lt;/h2&gt;

&lt;p&gt;Survivorship was actually the second leak to reach production. The first was subtler, and it’s where most of the testing in the rest of this post came from.&lt;/p&gt;

&lt;p&gt;In March 2025, while analyzing the returns of a newer model, I started to worry that there was leakage in the older one. So, I compared two ways of training the same model. One trained incrementally, one rebalancing period at a time, exactly as it would run live and exactly as walk-forward requires. The other trained over the whole period at once. Given the same data and the same settings, they should have produced the same results, but the annualized returns were different.&lt;/p&gt;

&lt;p&gt;I asked the LLMs I was working with to explain the difference and they couldn’t. The pull request I opened to debug it says so directly: “The LLMs appear to be unable to determine why the annualized returns for leakage_check.py and train_and_predict.py differ. Let’s roll up our sleeves and figure this out.”&lt;/p&gt;

&lt;p&gt;Rolling up my sleeves meant writing a logger. I logged every call to &lt;code&gt;fit()&lt;/code&gt; and&lt;code&gt;predict()&lt;/code&gt;, along with the shape and columns of every input, to a JSON file without timestamps, ran both paths and diffed the files. Then I shortened the run until I had the smallest period that still showed a difference and stepped through it in the debugger.&lt;/p&gt;

&lt;p&gt;The difference was in the shape of the training matrix. Which columns it had, and which rows survived a filter for missing values, depended on the data loaded for the whole run rather than just the training window. When training all at once, the model for an early period was shaped by companies whose data only began years later. When training incrementally, it didn’t know those companies existed yet. Neither path was reading a future price directly, but the future was deciding what the training data looked like, and that turned out to be enough to change the results.&lt;/p&gt;

&lt;p&gt;The comparison that found the leak became a test: train incrementally on part of the data, continue on the rest, and the picks must be bit-for-bit identical to training on all of it from scratch. It started as a script that I ran by hand, then became the code path that production uses to train, and it now runs every week in the automated test suite. If I could only keep one test from this whole project, it would be this one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fix That Switched Off Most of the Model
&lt;/h2&gt;

&lt;p&gt;Unfortunately, the March 2025 refactor fixed the leak and broke something else, and nothing noticed for thirteen months.&lt;/p&gt;

&lt;p&gt;Near the end of the data-preparation step, the refactored code selected the training columns by matching column names against a list of ticker symbols. The raw return column for each stock is named after its ticker, so it matched. However, the engineered features (moving averages and volatility measures built from those returns) have the ticker as a prefix rather than as the whole name, so they didn’t match and were dropped. A later step, which lines up every iteration’s columns with the model’s expected list of features, then quietly put them back, filled with zeros.&lt;/p&gt;

&lt;p&gt;The model ran, the tests passed and the features were all present in the matrix. Every one of them was zero, and that version went into production along with the leak fix.&lt;/p&gt;

&lt;p&gt;It finally came out in April 2026, while an LLM and I were wiring a new family of features into the training pipeline. Earlier that same day we had found a different silent drop, where three new settings were decoded from the model’s configuration and then never passed to the model. When we looked at how much the trained models relied on each input (their feature importance), every engineered feature had an importance of exactly zero.&lt;/p&gt;

&lt;p&gt;The fix went in behind a flag so that it could be compared with the old behaviour, and a week later it became the default. If you read my last post, you may recall a change that did nothing, where two runs came back bit-for-bit identical. This is the same smell from a different angle, and I now treat an exact zero with the same suspicion as an exact match.&lt;/p&gt;

&lt;h2&gt;
  
  
  Corporate Actions Keep Coming Back
&lt;/h2&gt;

&lt;p&gt;Most of the leaks I found in 2026 came from the same place: splits, reverse splits and dividends, which are known as corporate actions.&lt;/p&gt;

&lt;p&gt;A quick primer, since everything below depends on it. A raw price is what a stock actually traded at on a given day. When a company does a 20-for-1 split, every share becomes 20 shares worth a twentieth as much, so the raw price drops 95% overnight even though no one lost a cent. A reverse split is the opposite: 200 shares become one, and the raw price jumps 200-fold. An adjusted price rewrites the history before each event so that the series is continuous, e.g. by dividing every price before a 20-for-1 split by 20, and it does something similar for dividends. Neither series is wrong. They answer different questions, and the bugs below all came from asking one series a question meant for the other.&lt;/p&gt;

&lt;p&gt;I told the stock-dividend story in&lt;a href="https://redgeoff.com/posts/ai-agents-test-gate/" rel="noopener noreferrer"&gt;my last post&lt;/a&gt;, where a test asserted a data convention that never occurs in practice. Here are three more.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Model Learned to Short Stock Splits
&lt;/h3&gt;

&lt;p&gt;In a long/short research line, which buys some stocks and bets against others by shorting them, so that it profits when they fall, one data source’s features were computed from raw prices rather than adjusted ones. So, when Amazon split 20:1 in June 2022, the raw series showed a one-day move of about −95%. Alphabet’s 20:1 split about six weeks later looked the same, and Tesla’s 3:1 split read as −67%.&lt;/p&gt;

&lt;p&gt;A −95% day dominates any ranking of stocks against each other, and the model’s momentum-style features, which look at how much a stock has risen or fallen recently, carried it for one to three months afterwards. The model learned that stocks with that shape made good shorts, but they weren’t failing companies. They had just split.&lt;/p&gt;

&lt;p&gt;A Copilot agent found it while comparing the same strategy across two data vendors. One vendor’s prices came pre-adjusted, the other’s feature panel had been built from raw prices, and the two short sides disagreed by far more than data noise should explain. A simple count shows the problem: in a 2019 sample, 9.7% of the symbols in the raw panel had a single-day move bigger than 50%, against 6.1% in the other vendor’s adjusted data.&lt;/p&gt;

&lt;p&gt;What I find interesting is why raw prices had been chosen in the first place. Adjusted prices rewrite the past, e.g. a 2022 split changes the adjusted price for 2018. That looks exactly like lookahead, so raw prices seemed like the safe choice. However, these features were ratios: a price today divided by a price from some days ago. For any window that doesn’t straddle a split, the split factor cancels out and raw and adjusted prices give identical values. For a window that does straddle a split, the adjusted ratio is the true economic return and the raw one is an artifact. In other words, the thing that looked like lookahead wasn’t, and the thing chosen to avoid it was the bug.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy0j4asf2sntehkzzm6dv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy0j4asf2sntehkzzm6dv.png" alt="Two-panel chart of Amazon from March to September 2022. Top: the raw price falls from about $2,450 to about $125 on the June 6 split, while the adjusted price runs straight through. Bottom: the one-month return computed from raw prices drops to about minus 95 percent for 21 trading days after the split; computed from adjusted prices it stays within its normal range, and the two lines are identical outside those 21 days." width="800" height="820"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Amazon’s 2022 split as raw and adjusted prices. The raw one-month return reads as a 95% crash for a month: the shape the model learned to treat as a good short.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Ratios Want Adjusted, Levels Want Raw
&lt;/h3&gt;

&lt;p&gt;The mirror image turned up about a month later. The same research line had a minimum-price filter so that it wouldn’t trade anything under $10, and it was being applied to adjusted prices.&lt;/p&gt;

&lt;p&gt;After a large reverse split, adjustment inflates a stock’s earlier history. A shell company that really traded at a fraction of a cent, and then did a reverse split of a few hundred to one, ends up with an adjusted history of tens to thousands of dollars. So, those names passed the $10 floor, were trained on and were shorted, and the backtest booked wins on positions that nobody could have actually held. Claude found this one while investigating short-side results that still looked wrong after the earlier fixes. Gating on the raw price instead took the number of candidate instances priced under $10 from 11,194 to zero.&lt;/p&gt;

&lt;p&gt;The rule I took from the pair is that a ratio wants adjusted prices, because it’s asking how much a holding changed, while a price level wants raw prices, because it’s asking what the stock actually traded at. Neither series is a safe default.&lt;/p&gt;

&lt;p&gt;After four layers of price corruption had been removed from that research line, its log summed it up plainly: the earlier positive results had been “largely the corruption we removed.”&lt;/p&gt;

&lt;h3&gt;
  
  
  The Screen in Front of Everything Was Leaking
&lt;/h3&gt;

&lt;p&gt;This last one is the one I find most instructive, because it was in the tool I use to decide what is worth testing in the first place.&lt;/p&gt;

&lt;p&gt;I screen new signal ideas (candidate inputs for the model) with a quick check that runs in seconds, before committing to a hyperparameter search that runs for days. It asks a simple question: on each past date, did ranking stocks by this signal put them in roughly the right order of what they did next? In September 2026, an agent using that screen to check a textbook momentum signal for another project found that the screen itself had two problems.&lt;/p&gt;

&lt;p&gt;The first was that it loaded prices through a function whose &lt;code&gt;adjusted&lt;/code&gt; flag defaults to&lt;code&gt;False&lt;/code&gt;, and which returns its price column under the key &lt;code&gt;"Adj Close"&lt;/code&gt; either way. The variable was named for adjusted prices, the column was named for adjusted prices and every statistic downstream said adjusted, but the data was raw.&lt;/p&gt;

&lt;p&gt;The second was that it built its universe once, for the whole run, from every company that had ever been in the index. On the dates checked, 42 to 47% of the names it was ranking on a given date weren’t index members on that date. Some joined later, which is lookahead, since companies are added to the index because they grew. Others had left years before.&lt;/p&gt;

&lt;p&gt;The tell had been sitting in the documentation for months, as a statistic with a note beside it saying “investigate”. It traced back to Chesapeake’s 1-for-200 reverse split in April 2020, the same reverse split from the survivorship investigation a year earlier. Here, raw prices turned it into a gain of more than 10,000%, and it was counted twice because the universe carried both the old and the new ticker. The problem also generalizes. Reverse splits tend to happen to companies in trouble, and companies in trouble are exactly what sits at the bottom of a ranking by recent performance, so any signal that sorts on losers is contaminated in the same direction.&lt;/p&gt;

&lt;p&gt;Fortunately, the decisions I had made with that screen were based on rank correlation, which only asks whether the stocks came out in the right order, not by how much, so a few enormous outliers barely move it. When the agent recomputed a signal on corrected data, its rank correlation hardly changed, so those decisions probably still stand. Two other columns in the screen’s output didn’t survive. A leak doesn’t always invalidate everything it touches, and most of the work is finding out which numbers it actually reached.&lt;/p&gt;

&lt;h2&gt;
  
  
  Time Has Two Dates
&lt;/h2&gt;

&lt;p&gt;Point-in-time doesn’t just mean the date on the row.&lt;/p&gt;

&lt;p&gt;Some data describes a period but only becomes public later. One data vendor only keys its quarterly company financials by the end of the quarter they describe. A company’s December quarter isn’t public until its annual report is filed, around the start of March for the largest companies, and the vendor then needs time to pick it up. A reporting lag of 45 trading days after the period end made those numbers “known” a week or two before the vendor would actually have had them. That setting had already stood out in my hyperparameter search results, and the vendor’s own documentation settled it, as the period end is the only date it provides. So, I removed the option.&lt;/p&gt;

&lt;p&gt;EDGAR, the SEC’s filing database, does record the filing date, so when I later needed historical share counts, I keyed them on the date they were filed, typically about five weeks after the quarter they describe. Keying on the period end would have used numbers that nobody could have known yet.&lt;/p&gt;

&lt;p&gt;One vendor field had no code bug at all. An earnings-surprise figure (how far a company’s reported earnings beat or missed what analysts expected) was being computed against the analysts’ average forecast as it stood after later revisions, rather than as it stood on the day the earnings came out. The fix was to rebuild it from point-in-time estimate snapshots, which meant dropping every year before the snapshots begin and about a fifth of the symbols, which had no snapshots at all. Sometimes an honest fix makes your dataset smaller.&lt;/p&gt;

&lt;h2&gt;
  
  
  The False Alarms
&lt;/h2&gt;

&lt;p&gt;Leakage can also go wrong in the other direction.&lt;/p&gt;

&lt;p&gt;In August 2025, in the middle of the survivorship work, two issues drafted with an AI’s help claimed there was lookahead in my volume filter and in how the code decided which symbols were available. Both read convincingly. When I traced the dates, though, the rebalancing decision happens at the end of the window the code was reading, so all of that data was already known. My reply on the first one starts, “Actually, I believe we DO NOT have a lookahead bias.”&lt;/p&gt;

&lt;p&gt;A year later, an agent flagged code that was, in its words, “target-leakage-shaped”: the training target also appears among the input features. It does, and at a glance it looks alarming. However, tracing every date boundary showed no lookahead, as the training window ends where the test window begins and returns are measured forward from the pick date. The agent’s follow-up claim, that the model must therefore be a simple momentum ranker, didn’t survive a measurement either. That’s two confident answers, each corrected by measuring rather than arguing.&lt;/p&gt;

&lt;p&gt;The repo’s instruction file for agents now says that any leakage claim must name the specific date boundary that it violates and cite the code path, and those boundaries are pinned by tests named &lt;code&gt;test_no_lookahead_*&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who Found What?
&lt;/h2&gt;

&lt;p&gt;When I went back through the issues and pull requests to write this post, the pattern was clearer than I’d remembered. I found the early leaks, the ones that reached production, from numbers that were too good or didn’t match: an impossible year and two training paths that disagreed. The 2026 leaks were mostly found by agents, and almost never while they were looking for leaks. They turned up while we were wiring new features, building a new test harness, comparing two data vendors or checking a rebuilt index against the real one, with me reviewing what came back. The agents also raised most of the false alarms.&lt;/p&gt;

&lt;p&gt;The tests mostly arrived after the leak that justified them. I don’t think that’s a failure. A test written before you’ve been bitten is a guess about where the bugs are, whereas a test written afterwards is a record of where they were.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making Leaks Show Up as Numbers
&lt;/h2&gt;

&lt;p&gt;Here’s what actually caught things, roughly in the order that I’d add them to a new project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Invariance.&lt;/strong&gt; A result for a past window must not depend on the future. Training incrementally must match training all at once, and moving a run’s end date must not change an earlier window. The March 2025 leak broke exactly this, and so did a similar one I found later in a different research line, where extending a run’s end date changed results for years that were already over.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Counts of the impossible.&lt;/strong&gt; Single-day moves beyond 50%, prices under a cent passing a $10 filter, feature importance of exactly zero, or a year of returns that no strategy has ever produced. Several of the leaks in this post would have shown up in a count like that well before they showed up in a result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Point-in-time by construction.&lt;/strong&gt; Resolve index membership per date, from the best source you can find, and key vendor fields on when they became knowable, not on the period they describe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compare against something real.&lt;/strong&gt; A copy of an index fund that beats the fund, or two vendors that disagree, is a leak or a data bug until proven otherwise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A pure-noise null.&lt;/strong&gt; Run the whole pipeline on random-walk prices, where there’s no signal by construction. If it finds one, it leaks. In one research line, after four leak fixes, the null finally sat on zero, and that was the result I trusted most.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replication on independent data.&lt;/strong&gt; When an agent hands you an encouraging statistic, rerun it on data it hasn’t seen before you believe it.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;This describes software I run on my own accounts. It is not investment advice and I do not offer investment services.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>data</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>I let AI agents write most of a live-trading codebase. Here's the gate that made it safe.</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Mon, 28 Sep 2026 23:50:00 +0000</pubDate>
      <link>https://dev.to/redgeoff/i-let-ai-agents-write-most-of-a-live-trading-codebase-heres-the-gate-that-made-it-safe-1hjf</link>
      <guid>https://dev.to/redgeoff/i-let-ai-agents-write-most-of-a-live-trading-codebase-heres-the-gate-that-made-it-safe-1hjf</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw1jmoyzq42000xv4v965.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw1jmoyzq42000xv4v965.jpg" alt="A lowered railroad crossing barrier with glowing red lights across a wet road at dusk, a train blurring past behind it" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: AI-generated&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For the last 21 months I have been the only engineer on TopSet, a system that trades real money. It picks a portfolio with machine-learning models, rebalances on a schedule, and executes through live broker APIs on infrastructure I own end to end. It is my own capital, not anyone else’s.&lt;/p&gt;

&lt;p&gt;Agents wrote most of the code. Claude Code, Cursor, Copilot. About 1,600 pull requests in those 21 months, which is more than I could have typed in three times the span.&lt;/p&gt;

&lt;p&gt;That leaves you with a choice everyone adopting these tools runs into. You can read every line the agent produces, in which case you have bought yourself a slower version of writing it yourself. Or you can skim, merge, and move fast, in which case you accumulate code that looks right and isn’t. On a system that places orders with real money, the second option ends with trades you didn’t intend.&lt;/p&gt;

&lt;p&gt;I took a third option: make something other than my attention the thing that decides what ships. Tests became the gate. Nothing merges or deploys without a green build, and my own reading moved up a level, to design, to test coverage, and to the handful of results I refuse to let change quietly.&lt;/p&gt;

&lt;p&gt;That worked. It also failed in ways I did not expect, and the failures are the interesting part, so I’ll spend most of this post there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I actually read
&lt;/h2&gt;

&lt;p&gt;“Tests are the gate” is not the same as “I stopped looking.” What changed is where I spend attention.&lt;/p&gt;

&lt;p&gt;Most pull requests get a light review. Research code I skim. Changes to the parts that decide what to buy or how to trade it, the model training and the execution paths, I read properly, looking for whether the approach is reasonable rather than whether every line is correct. The tests cover the lines. I cover the idea.&lt;/p&gt;

&lt;p&gt;Then there is one rule I do not bend. If a change moves a snapshot, or shifts the result of an end-to-end test, that is a stop. Snapshots and integration results are supposed to be stable, so a diff in one of them means either the change did something I didn’t intend, or it did something I did intend and I now owe an explanation. An agent will happily regenerate a snapshot to make a build go green. That is the single most dangerous thing these tools do, and it is why the snapshot files live in the repo where a diff is visible in review.&lt;/p&gt;

&lt;p&gt;For anything involving a calculation I have not verified before, the tests are not enough either. I have the agent write a report script, and there are now 161 of them, that dumps the pipeline to CSV. I open the CSV in a spreadsheet and check the arithmetic by hand: return per trade, slippage, annualized return. Then I spot-check inputs, picking a few prices and going back to the raw data directory to confirm those were the prices the system actually used.&lt;/p&gt;

&lt;p&gt;It is slow and it is not clever, and it has caught things nothing else would. A test asserts that a function returns what the author believed it should return. A spreadsheet asks whether the number is true.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the gate is
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc5972cjk8omdu4c79qpj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc5972cjk8omdu4c79qpj.png" alt="Diagram of the test gate: every agent pull request runs lint, types, about 7,500 tests, an empty-database check, a migration round trip and terraform validate before it can merge and deploy. A weekly suite runs end-to-end rebalancings, a 100-run flake hunt, training snapshots and leakage checks against main. Production errors page me on Discord, and every fix comes back through the same gate. Underneath: what I still check myself." width="800" height="1040"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every pull request runs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lint (ruff) and type checking (mypy)&lt;/li&gt;
&lt;li&gt;about 7,500 tests across 331 test modules&lt;/li&gt;
&lt;li&gt;an assertion that the test database is empty afterward&lt;/li&gt;
&lt;li&gt;a migration rollback-and-reapply, all the way to base and back&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform validate&lt;/code&gt; against both AWS accounts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any of that fails, nothing merges. The build is the merge gate, and it is not advisory.&lt;/p&gt;

&lt;p&gt;Once a week, on a schedule, a heavier set runs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;two end-to-end rebalancing runs against a mock broker&lt;/li&gt;
&lt;li&gt;the same integration test 100 times in a row, looking for flakes&lt;/li&gt;
&lt;li&gt;nine deterministic model-training snapshot runs, pinned inside Docker&lt;/li&gt;
&lt;li&gt;two leakage checks on the training pipeline&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Running the same integration test 100 times only makes sense because the test is not the same each time. The mock broker fills orders probabilistically: a 20% chance per 10-second cycle, 70% of those complete and the rest partial at a random size, at random prices. Every iteration produces a different interleaving of fills, partial fills and timing. A hundred runs is a search for race conditions, not a hundred repeats of one path.&lt;/p&gt;

&lt;p&gt;What it finds are real concurrency bugs wearing flaky-test costumes. Worker threads leaking between tests. A queued task waking up after teardown had already deleted the row it wanted. A data loader that wasn’t thread-safe and corrupted a shared index under load. Each one showed up first as “that test fails sometimes.”&lt;/p&gt;

&lt;p&gt;The weekly set exists because a flaky gate is worse than no gate. If a test fails once every thirty runs, and twenty agent PRs land in a week, that one test goes red most weeks. Have a few like it and something red is always on screen, and you start ignoring red. Hunting flakes is not hygiene here. It is what keeps the gate meaningful.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tests that matter are about money, not functions
&lt;/h2&gt;

&lt;p&gt;Unit tests are cheap and agents write them happily. They are not what I trust.&lt;/p&gt;

&lt;p&gt;What I trust are end-to-end tests that drive a full rebalancing against a mock broker, with the awkward parts turned on. They’re named after the ways money goes wrong:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;orders that have to be resubmitted&lt;/li&gt;
&lt;li&gt;a rebalancing that resumes from the middle, with partial fills already on the books&lt;/li&gt;
&lt;li&gt;a resume that has both buys and sells outstanding&lt;/li&gt;
&lt;li&gt;smart orders cancelled mid-flight, on the sell side and then the buy side&lt;/li&gt;
&lt;li&gt;deposits and repeating withdrawals arriving while a rebalancing is in progress&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are exactly the control flows a language model gets plausibly wrong. Interrupted work, partial state, money arriving in the middle of an operation: the code for each of these reads fine in isolation. It’s the interaction that bites.&lt;/p&gt;

&lt;p&gt;Here is one that made it past review and got caught by the constraint at the bottom of the stack. When the last pending buy of a rebalancing had its amount adjusted for pending withdrawals, the adjusted value could land on exactly zero. The existing guard raised an error on a negative amount, but zero isn’t negative. The affordability check, &lt;code&gt;available_cash &amp;gt;= amount&lt;/code&gt;, was &lt;code&gt;0 &amp;gt;= 0&lt;/code&gt;, so it passed. The order was promoted, and the database rejected it: &lt;code&gt;amount &amp;gt; 0&lt;/code&gt; is a check constraint on that table.&lt;/p&gt;

&lt;p&gt;The interesting part is what that did to the retry. The integrity error fired inside the same transaction that carried the completing order’s status update, so the rollback discarded that too. The scheduler came back around, found identical inputs, and did it again. Not a self-healing retry: a stuck rebalancing.&lt;/p&gt;

&lt;p&gt;The fix took three attempts, and the second one is the useful story. Gating the promotion on &lt;code&gt;amount &amp;gt; 0&lt;/code&gt; looks correct and does nothing, because the code had already assigned the adjusted value to a live ORM object. That marked it dirty, and the next autoflush in the same transaction persisted the zero regardless of whether the order was ever promoted. The condition guarded the decision, not the mutation.&lt;/p&gt;

&lt;p&gt;I only know that because the failure was reproduced live against &lt;code&gt;main&lt;/code&gt; before any fix was written, and the first fix was re-run against that same repro rather than checked by reading the code. When an agent is writing the patch, “I read it and it looks right” is the single least reliable signal available to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways a green build lied to me
&lt;/h2&gt;

&lt;p&gt;This is the part I’d want to read, so here are the three worst cases, all real, all from this codebase.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The test asserted a convention that does not exist
&lt;/h3&gt;

&lt;p&gt;Corporate actions have to be applied to historical prices, and stock dividends are the fiddly ones. My broker’s API returns a &lt;code&gt;rate&lt;/code&gt; for each. The code treated that rate as a bare fraction: a 5% stock dividend arrives as &lt;code&gt;0.05&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It isn’t. It’s the ratio of new shares to old. Every one of the 101 stock-dividend records across 43 symbols in my data has a rate of at least 1.0016. Not one is a bare fraction. The convention the code assumed does not occur in the data at all.&lt;/p&gt;

&lt;p&gt;The unit test passed, because the test asserted the same wrong convention with a fixture value of &lt;code&gt;rate: 0.05&lt;/code&gt;, a number that cannot appear in production. The test and the code were wrong in exactly the same way, which is what you get when both are written in the same sitting from the same misunderstanding.&lt;/p&gt;

&lt;p&gt;The effect was that each stock dividend roughly halved the adjusted price, and it compounded across events. One symbol with nine of them came out deflated by about 490×, turning a real price history into a fake ramp of more than a thousand-fold over the period. And because every price stayed between a few cents and a few hundred dollars, a check for implausible price levels would not have flagged it either.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxnopy8b0eob0d5yi35jj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxnopy8b0eob0d5yi35jj.png" alt="Log-scale chart of Southern Copper (SCCO) adjusted close from 2016 to 2026. The fixed series runs from about $15 to $200. The buggy series starts about 490 times lower, near 3 cents, and steps up at each of nine stock-dividend ex-dates in 2024 to 2026 until it meets the fixed series." width="800" height="540"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Southern Copper’s real daily prices, adjusted twice by the same code. The only difference is whether the stock-dividend factor is 1 / rate or 1 / (1 + rate).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The fix was a corrected fixture, plus a regression test that runs a nine-event sequence and asserts the cumulative adjustment factor stays sane. The lesson I took: a fixture is a claim about the world, and nobody reviews fixtures.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The test passed on NaN
&lt;/h3&gt;

&lt;p&gt;In a research tool, an agent added a second way to select a model configuration and reported the result in the PR: 100% agreement with the existing selector, at every sample size tried.&lt;/p&gt;

&lt;p&gt;That number was not real. The tool built its pool from a source that was missing the columns the default scoring version needs, so every score came out NaN. With all scores NaN, the selector fell through to a fixed tie-break order, which of course agrees with itself 100% of the time at every sample size.&lt;/p&gt;

&lt;p&gt;The test that was supposed to cover this had been passing on those same NaN scores for as long as it had existed. It never checked anything. Green, meaningless, and quoted in a PR description as a finding.&lt;/p&gt;

&lt;p&gt;The follow-up PR made the condition a hard error rather than a silent NaN, pinned the test to a scoring version where the columns exist, and added guards. It also flagged that an older result produced the same way might carry the same artifact. That is the right instinct: when you find a lie, go and check what else it told you.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The change did nothing at all
&lt;/h3&gt;

&lt;p&gt;An agent wired a new training target through what looked like the right code path. The first screen ran clean and produced numbers bit-for-bit identical to the baseline. Every metric, to four decimal places.&lt;/p&gt;

&lt;p&gt;Identical results are not a pass. They’re a smell. Two different configurations producing byte-equal output usually means one of them didn’t happen.&lt;/p&gt;

&lt;p&gt;It hadn’t. The runner always sets a parameter that routes execution to a completely separate function, which builds its own training target and never looked at the new field. Unpickling both runs and diffing the actual selections showed 238 of 238 identical picks for the test year. After the real fix, 0 of 238 were identical, and a regression test now asserts the two modes produce different output.&lt;/p&gt;

&lt;p&gt;Nothing failed. The compute was spent. The result would have gone into the research log as “no effect,” which is a conclusion, and it would have been wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  The shape of all three
&lt;/h3&gt;

&lt;p&gt;In every case the build was green, and the number was wrong. Tests prove that the code does what the tests say. They say nothing about whether what the tests say is true, whether the code under test ran at all, or whether the data going in is what you think.&lt;/p&gt;

&lt;p&gt;That is the agent-era failure mode, and it is worse with agents than without them, for a simple reason: an agent writes the code and the test together, from one reading of the problem. If the reading is wrong, both artifacts are wrong, and they agree. A human pair would at least have had two readings.&lt;/p&gt;

&lt;p&gt;What I do about it now, concretely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Distrust results that are identical, unchanged, or perfect. Check the output, not the exit code.&lt;/li&gt;
&lt;li&gt;Treat fixtures as claims. If a fixture value can’t occur in production, that’s a bug in the test.&lt;/li&gt;
&lt;li&gt;Make impossible states loud. NaN, missing data, and empty inputs should raise, not flow through and produce a number.&lt;/li&gt;
&lt;li&gt;When something is found to be wrong, go back and check what else that thing told you.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The reviewer that isn’t a test
&lt;/h2&gt;

&lt;p&gt;Some mistakes are not code-shaped and no test will ever catch them.&lt;/p&gt;

&lt;p&gt;So I added a second kind of review: a deliberately skeptical reviewer persona, run against a finished result rather than a diff, with instructions to argue that the result is not real. I iterated on the persona with Claude until it stopped being agreeable.&lt;/p&gt;

&lt;p&gt;It found things I am glad it found. That a configuration had been tuned by repeatedly checking results on data I had promised myself I would only look at once, so my holdout wasn’t a holdout any more. That a cost model was running with zero financing cost while the strategy it priced used nearly four times leverage.&lt;/p&gt;

&lt;p&gt;Neither is a bug. Both are the kind of error that invalidates a conclusion, and no test suite in the world was going to tell me.&lt;/p&gt;

&lt;h2&gt;
  
  
  The gate after the gate
&lt;/h2&gt;

&lt;p&gt;CI stops caring the moment something merges. After that the system runs unattended, on a schedule, against a live broker, and the question changes from “is this code correct” to “is this thing behaving right now.”&lt;/p&gt;

&lt;p&gt;Every ERROR the system logs in production becomes a CloudWatch alarm that posts to a Discord channel on my phone. That is the whole alerting stack, and for a one-person operation it is enough: I am not running a rotation, I just need to know.&lt;/p&gt;

&lt;p&gt;The loop from there is the same one I use for everything else. Point an agent at the production logs, hand it a local copy of the database from around the failure, ask for a diagnosis and a fix with a test. The logs and the data are usually enough for it to find the problem, and the test it writes is the thing that stops the problem coming back. Several of the bugs in this post arrived that way rather than through CI.&lt;/p&gt;

&lt;p&gt;Worth saying plainly: the tests did not catch those. The tests caught the next occurrence.&lt;/p&gt;

&lt;h2&gt;
  
  
  What stays human
&lt;/h2&gt;

&lt;p&gt;Architecture. Test design. What “done” means. Merge judgment when the tests pass and something still feels off.&lt;/p&gt;

&lt;p&gt;And one more thing that turned out to matter: the repo’s own instruction file. Every time an agent reached a wrong conclusion in a way another agent would repeat, I wrote the correction down there. One rule says that any claim of data leakage must name the specific date boundary it violates, because two different agents had asserted leakage from reasoning alone, and both were wrong. That file is now a list of the mistakes this codebase invites. It’s the closest thing I have to institutional memory for a team of one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it cost
&lt;/h2&gt;

&lt;p&gt;The per-PR suite takes about ten minutes. That is the tax on every change, and it is the number I would defend hardest: ten minutes is short enough that I never route around it, and long enough to run tests that touch a database and a fake broker.&lt;/p&gt;

&lt;p&gt;The machine bill is every one of the 3,000 GitHub Actions minutes my plan includes, plus roughly $20 a month for extra minutes on top. The agents themselves are Claude Pro and Cursor Pro, $20 each. I also paid $40 a month for Copilot until GitHub moved it to per-token billing, which would have raised my bill more than tenfold, so that work moved to Claude Code and Cursor. So the tools that wrote most of this codebase cost tens of dollars a month, like the compute spent checking them, and neither is what the project actually cost.&lt;/p&gt;

&lt;p&gt;What it actually cost is fixtures and flakes. Writing a mock broker that fails in realistic ways, maintaining a self-contained dataset so model training can be tested at all, and then the long tail of chasing tests that fail once in thirty runs. None of that is glamorous and all of it is load-bearing. Every hour I skipped there came back later as an hour of not being able to trust a result.&lt;/p&gt;

&lt;p&gt;And sometimes the gate itself is the thing that’s broken. The 100-run soak lives in a shell script rather than inline in CI, because the inline version ran under a POSIX shell where &lt;code&gt;{1..100}&lt;/code&gt; isn’t brace expansion. It was a literal string. The loop ran exactly once, and reported success, for longer than I’d like to admit.&lt;/p&gt;

&lt;p&gt;The tests are not where I over-built. Every gate in this post exists because something broke, or nearly did, and the existing checks let it through. I would add all of them again.&lt;/p&gt;

&lt;p&gt;Where I over-built is everything the tests had to cover.&lt;/p&gt;

&lt;p&gt;I started TopSet expecting to turn it into a product, so I built it for customers who never existed. A bot lifecycle with eleven kinds of change request, each one a queued, locked, asynchronous workflow object, so that deposits and withdrawals and stops could be requested safely by someone who wasn’t me. Two broker integrations instead of one. A staging environment that mirrors production, behind a VPN. Cross-account backups with compliance-grade retention locks on a database that holds my own trades.&lt;/p&gt;

&lt;p&gt;For one person running their own accounts, several of those could have been a script I ran by hand while watching it.&lt;/p&gt;

&lt;p&gt;That is the part that compounds, and it is why I am putting it in a post about testing. Every one of those surfaces is something the gate has to cover. The change requests need end-to-end tests for money arriving mid-rebalance. Two brokers means two of everything, including the mocks. The staging environment is a second place for migrations to fail. I did not pay for the product shape once, in the building. I have paid for it every week since, in the size of the harness that has to keep it honest.&lt;/p&gt;

&lt;p&gt;If I were starting again for a book of one, I would build the trading and the research properly and leave the product machinery until somebody asked for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you’re rolling this out to a team
&lt;/h2&gt;

&lt;p&gt;I’ve done this alone, with tests I wrote and one person’s judgment. That is not the same problem as a team of fifteen, and I’d be careful about anyone who tells you otherwise. But some of it transfers, and the ordering I’d insist on comes from a team I did run: at a healthcare company, requiring automated tests on every PR is what took active medium and high bugs down 72% and weekly hotfixes from 7 to 1.5. That was before agents. It’s the same first move.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fix the gate before you raise throughput.&lt;/strong&gt; Coverage on the paths that lose money or data, and no tolerated flakes. Agents multiply whatever your CI already is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The author owns the change, whoever typed it.&lt;/strong&gt; “The agent wrote it” is not a review comment, and it is not a defense in a postmortem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review the result, not the diff.&lt;/strong&gt; For anything that produces a number, ask what would look different if the change had done nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure escaped defects and hotfix rate.&lt;/strong&gt; Not lines, not PR counts. Agents make those metrics meaningless overnight.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The part I would not change: the gate is what let one person move at this speed on a system where mistakes cost real money. The part I underestimated: a gate is a claim about correctness, and claims need checking too.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This describes software I run on my own accounts. It is not investment advice and I do not offer investment services.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>testing</category>
      <category>devops</category>
      <category>programming</category>
    </item>
    <item>
      <title>Turnkey Data Analysis Using DuckDB and Metabase for PostgreSQL &amp; CloudWatch</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Fri, 01 Mar 2024 13:05:39 +0000</pubDate>
      <link>https://dev.to/redgeoff/turnkey-data-analysis-using-duckdb-and-metabase-for-postgresql-cloudwatch-2cck</link>
      <guid>https://dev.to/redgeoff/turnkey-data-analysis-using-duckdb-and-metabase-for-postgresql-cloudwatch-2cck</guid>
      <description>&lt;p&gt;How we used DuckDB and Metabase to streamline our data analysis workflow, enabling us to build an email list to contact our frequent users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjzfevlv2bgx502g58i7b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjzfevlv2bgx502g58i7b.png" alt="A cartoon duck with glasses sitting at a computer whose screen reads QuackMeUp" width="686" height="686"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Data Analysis with DuckDB and Metabase. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Back in July 2023, my friend and I were excited about building something with a Large Language Model (LLM). At that time, we noticed ChatGPT had no native internet access. ChatGPT did roll out a beta feature providing Bing search access, but it was retracted shortly after its release. We observed several ChatGPT plugins offering internet access, but none were free. Anticipating OpenAI’s reintroduction of Bing search, we decided to quickly develop our own web search plugin for ChatGPT to attract some users.&lt;/p&gt;

&lt;p&gt;After spending a few days coding and setting up AWS infrastructure, we successfully launched our MindfulDataAI Search Plugin in the ChatGPT Plus store. Impressively, OpenAI approved our plugin within hours. Within days, we observed thousands of web searches being conducted through our plugin. This success spurred us to explore other ideas, such as developing business tools for ChatGPT. We knew our plugin’s relevance might be short-lived, but we were hopeful that we could identify a business-specific problem before then. Indeed, this was underscored in September 2023 when ChatGPT reintroduced Bing search.&lt;/p&gt;

&lt;p&gt;Surprisingly, even after the reintroduction of ChatGPT’s native Bing search, a significant number of users continued using our plugin. Intrigued by this preference, we sought to understand the underlying reasons.&lt;/p&gt;

&lt;p&gt;Our challenge was to analyze user data efficiently. User activities were logged, and email addresses were stored in a PostgreSQL database. Initially, we used CloudWatch Insights to identify the most active users, followed by PostgreSQL queries to look up their email addresses. This method was effective but disjointed. I was also looking for an opportunity to experiment more with DuckDB, so I decided to create an open-source repository, called &lt;a href="https://github.com/redgeoff/QuackMeUp" rel="noopener noreferrer"&gt;QuackMeUp&lt;/a&gt;, along with a guide to help others perform this type of data analysis more efficiently.&lt;/p&gt;

&lt;p&gt;In the following sections, we’ll discuss how we used DuckDB and Metabase to streamline our data analysis workflow, enabling us to build an email list so that we could contact our users to understand why they still preferred our plugin.&lt;/p&gt;
&lt;h2&gt;
  
  
  DuckDB &amp;amp; Metabase
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://duckdb.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;DuckDB&lt;/strong&gt;&lt;/a&gt; is an in-memory, columnar database optimized for quick analytical queries. Its main advantages are speed, ease of setup, and SQL compatibility. It’s particularly useful for fast data analysis without heavy resource requirements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.metabase.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Metabase&lt;/strong&gt;&lt;/a&gt; is a user-friendly, open-source BI tool. It allows easy data querying and visualization, even for non-technical users. Metabase supports various data sources and is known for its intuitive interface and collaboration features.&lt;/p&gt;
&lt;h3&gt;
  
  
  Why Use Them?
&lt;/h3&gt;

&lt;p&gt;For MindfulDataAI, DuckDB offers the speed we need for analyzing logs and PostgreSQL data, while Metabase makes data visualization and sharing straightforward. This combination aims to streamline our data analysis, merging different data sources efficiently and reducing complexity.&lt;/p&gt;

&lt;p&gt;Next, we’ll explore how we integrated these tools into our workflow and the insights we gained.&lt;/p&gt;
&lt;h2&gt;
  
  
  High-Level Overview of the Solution
&lt;/h2&gt;

&lt;p&gt;Let’s start with an overview of the key components of our solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modify the app’s code so that it logs in JSON format.&lt;/li&gt;
&lt;li&gt;Deploy a scheduled AWS Lambda function that will automate the export of CloudWatch logs to an S3 bucket.&lt;/li&gt;
&lt;li&gt;Download the logs from the S3 bucket using the &lt;code&gt;aws s3 sync&lt;/code&gt; command.&lt;/li&gt;
&lt;li&gt;Run a Python script to extract JSON segments from the logs and save them as &lt;code&gt;.json&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;Configure DuckDB to connect to your PostgreSQL instance and to access these &lt;code&gt;.json&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;Use Metabase for business intelligence. This setup will enable you to join datasets and create useful analytics dashboards.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is how the pipeline works:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftzubihovr7n3tnw4m16j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftzubihovr7n3tnw4m16j.png" alt="Flow diagram: app code writes JSON logs, an AWS Lambda function exports them to S3, aws s3 sync downloads them, format_logs.py extracts and saves the JSON, DuckDB points to Postgres and the JSON logs, and Metabase is used for analysis" width="594" height="1206"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;End-to-End Data Pipeline for Business Analytics. Image credit: Author&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The Detailed Solution
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Download the GitHub repo
&lt;/h3&gt;

&lt;p&gt;To make it faster to get started, I’ve packaged all the code in a GitHub repo that you can download with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone https://github.com/redgeoff/QuackMeUp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, &lt;code&gt;cd QuackMeUp&lt;/code&gt; so that you are ready for the next steps.&lt;/p&gt;
&lt;h3&gt;
  
  
  Install the dependencies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Install Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" rel="noopener noreferrer"&gt;Install the awscli&lt;/a&gt; and run &lt;code&gt;aws configure&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Install Python, e.g. &lt;code&gt;brew install python@3.11&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;python3.11 -m pip install poetry&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;poetry install&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Install the Git hooks for code formatting with black: &lt;code&gt;poetry run pre-commit install&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://duckdb.org/docs/installation/" rel="noopener noreferrer"&gt;Install DuckDB&lt;/a&gt;, e.g. &lt;code&gt;brew install duckdb&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Configure the .env file
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cp .env.example .env&lt;/code&gt; and then edit &lt;code&gt;.env&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Choose a value for &lt;code&gt;TERRAFORM_BUCKET_NAME&lt;/code&gt; that will be unique across all AWS users, e.g. &lt;code&gt;myorg-quackmeup-terraform-bucket&lt;/code&gt;, where &lt;code&gt;myorg&lt;/code&gt; is a unique name for your organization. This bucket will be used to remotely store your Terraform state.&lt;/li&gt;
&lt;li&gt;Choose a value for &lt;code&gt;LOGS_BUCKET_NAME&lt;/code&gt; that will be unique across all AWS users, e.g. &lt;code&gt;myorg-quackmeup-logs&lt;/code&gt;, where &lt;code&gt;myorg&lt;/code&gt; is a unique name for your organization. This bucket will be used to store logs exported from CloudWatch.&lt;/li&gt;
&lt;li&gt;Be sure to substitute the value of &lt;code&gt;PG_CONNECTION_STRING&lt;/code&gt; with the connection string for your Postgres instance. Ideally, you’d use the connection string for a read replica.&lt;/li&gt;
&lt;li&gt;You can leave the rest of the values in &lt;code&gt;.env&lt;/code&gt; intact unless you prefer them to be different.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Deploy the infrastructure
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli#install-terraform" rel="noopener noreferrer"&gt;Install Terraform&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Load the AWS Console and manually create an S3 bucket with the same name that you specified for &lt;code&gt;TERRAFORM_BUCKET_NAME&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffis70v5cls7mxlszbsi5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffis70v5cls7mxlszbsi5.png" alt="The AWS Console Create bucket form for the Terraform state bucket" width="800" height="584"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Create S3 bucket for Terraform state. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Initialize the terraform environment: &lt;code&gt;./terraform/init.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Make sure the terraform plan doesn’t error out: &lt;code&gt;./terraform/plan.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The following &lt;code&gt;apply.sh&lt;/code&gt; script will then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an S3 bucket for &lt;code&gt;LOGS_BUCKET_NAME&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create an ECR repository for the Lambda code&lt;/li&gt;
&lt;li&gt;Build and push a Docker image to this ECR repository&lt;/li&gt;
&lt;li&gt;Schedule a Lambda (using the Docker image) that will export the latest CloudWatch logs to the S3 bucket every 4 hours&lt;/li&gt;
&lt;li&gt;Create IAM policies and roles as needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Deploy the infrastructure with &lt;code&gt;./terraform/apply.sh&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Tag target logs for export
&lt;/h3&gt;

&lt;p&gt;Open the AWS Console and navigate to the &lt;em&gt;CloudWatch Log Groups&lt;/em&gt; page. For each log that you wish to be exported to S3, simply add a tag with Key=&lt;code&gt;ExportToS3&lt;/code&gt; and Value=&lt;code&gt;true&lt;/code&gt;. The log exporter Lambda runs every 4 hours so you’ll have to wait at least 4 hours before you start seeing any data in the S3 bucket.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxeed0d08lnr0vdjy2mvo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxeed0d08lnr0vdjy2mvo.png" alt="The CloudWatch Log Groups page with an ExportToS3 tag set to true" width="800" height="237"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Tag CloudWatch logs for export. Image credit: Author&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Install QuackMeUp
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create the DuckDB instance: &lt;code&gt;./scripts/duckdb/create_db.sh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Attach the Postgres instance to DuckDB: &lt;code&gt;./scripts/duckdb/attach_postgres.sh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Build the Docker image that will run Metabase with DuckDB support: &lt;code&gt;./scripts/metabase/build_docker.sh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run the Docker containers: &lt;code&gt;docker-compose up -d&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Seed the Metabase config so that you can just log in: &lt;code&gt;./scripts/metabase/import_db.sh&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Execute the pipeline
&lt;/h3&gt;

&lt;p&gt;After the logs have been updated, run the following pipeline to ingest the updated data into DuckDB:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;s3 sync&lt;/code&gt; to download the logs from S3: &lt;code&gt;./scripts/s3/download_logs.sh&lt;/code&gt;. Note: if you have a lot of data, this can take a while when it is first run.&lt;/li&gt;
&lt;li&gt;Run a Python script to extract the JSON payloads in the logs so that they can be analyzed with DuckDB: &lt;code&gt;make format_logs&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a DuckDB table pointing to the extracted logs: &lt;code&gt;./scripts/duckdb/import_logs.sh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Restart Metabase so that it loads the updated DuckDB: &lt;code&gt;docker restart quackmeup-metabase-1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Accessing Metabase
&lt;/h3&gt;

&lt;p&gt;You can then access Metabase by visiting &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; and logging in with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Email: &lt;code&gt;quackmeup@example.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Password: &lt;code&gt;E!v_#nc$48pqfZJ&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Troubleshooting
&lt;/h3&gt;

&lt;p&gt;DuckDB is incredibly fast because it stores a substantial amount of data in memory. If you encounter errors related to insufficient memory, it’s advisable to open the Docker console and increase the memory allocation. In our experience, for processing 3GB of zipped logs, we needed to increase the memory allocation to 10GB. Alternatively, you can modify the &lt;code&gt;format_logs.py&lt;/code&gt; script so that it filters out any JSON data that you don’t need.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example Analysis
&lt;/h2&gt;

&lt;p&gt;Now that we’ve got QuackMeUp running, we can start doing some data Analysis. The following section is specific to our data, but it will help you to visualize the power of the QuackMeUp Analytics pipeline.&lt;/p&gt;

&lt;p&gt;Recall that in the case of MindfulDataAI, we want to get the email addresses of all the frequent users. In our particular case, the search requests are logged in payloads like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"json"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"asctime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-08 23:57:51,020"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my_logger"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"levelname"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"INFO"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Response"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"RESPONSE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"method"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"GET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/search"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="s2"&gt;"number of tourists in Orlando 2022"&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To start, we can look at things like the number of searches each month:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
 &lt;span class="k"&gt;SUBSTRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'asctime'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;num_searches&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;JSON_EXTRACT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.code'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'"RESPONSE"'&lt;/span&gt;
 &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;JSON_EXTRACT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.request.path'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'"/search"'&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt; &lt;span class="k"&gt;ASC&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can run this query in Metabase by creating a new &lt;em&gt;Question&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmci4iazthett1uf563g3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmci4iazthett1uf563g3.png" alt="A Metabase question with the SQL query for searches per month" width="800" height="463"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Metabase query for searches per month. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And then you can render a nice-looking visualization:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqhw455544u6cn347l41d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqhw455544u6cn347l41d.png" alt="A Metabase chart of monthly searches rising in August 2023 and then roughly halving each month" width="800" height="539"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Monthly searches. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note: You may notice from our data that it contrasts with the typical “up and to the right” trend. We launched the plugin in late July, which led to a significant increase in searches in August. However, in September, OpenAI reintroduced native Bing search support in ChatGPT. Since then, the number of searches using our plugin has nearly halved each month! 😱. Nonetheless, we still retain a user base, and we are interested in contacting them to understand why they prefer our plugin over the native Bing search.&lt;/p&gt;

&lt;p&gt;We utilize Supabase and its OAuth integrations, which means the users’ email addresses are stored in a PostgreSQL table named &lt;code&gt;users&lt;/code&gt;. By joining the &lt;code&gt;searches&lt;/code&gt; and &lt;code&gt;users&lt;/code&gt; using the &lt;code&gt;user_id&lt;/code&gt;, we can compile a list of users with the highest number of searches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt;
 &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num_searches&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first_search&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_search&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raw_user_meta_data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="k"&gt;SELECT&lt;/span&gt;
 &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;num_searches&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'request'&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'headers'&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'MINDFULDATAAI_USER_ID'&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="k"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SUBSTRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'asctime'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;first_search&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="k"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SUBSTRING&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'asctime'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;last_search&lt;/span&gt;
 &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt;
 &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;JSON_EXTRACT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.code'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'"RESPONSE"'&lt;/span&gt;
 &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;JSON_EXTRACT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$.request.path'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'"/search"'&lt;/span&gt;
 &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
 &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num_searches&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And when run, Metabase will give you a table of data that can easily be exported to a CSV file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F43a1fc2eqxiv1sj4gd4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F43a1fc2eqxiv1sj4gd4a.png" alt="A Metabase table of the ten most active users with search counts, first and last search dates, and redacted names and emails" width="799" height="310"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We just joined the JSON log data (searches) with the Postgres data (users) in a single query using DuckDB. Isn’t that cool?! 😎&lt;/p&gt;

&lt;p&gt;Although this solution was somewhat more complex than necessary, it has provided us with a robust pipeline that enables further analysis through the crafting of new SQL queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternative Solutions
&lt;/h2&gt;

&lt;p&gt;While the combination of DuckDB and Metabase presents an efficient and effective approach for data analysis in our scenario, it’s important to consider alternative solutions that might better align with different requirements or preferences. For example, you may want to consider a hosted version of Metabase that can be shared with your coworkers. Alternatively, you might prefer not to have to re-execute the entire pipeline whenever there are changes. Here are some noteworthy alternatives:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Using Presto or Athena for Querying:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://prestodb.io/" rel="noopener noreferrer"&gt;Presto&lt;/a&gt;, an open-source distributed SQL query engine, and &lt;a href="https://aws.amazon.com/athena/" rel="noopener noreferrer"&gt;Athena&lt;/a&gt;, the AWS managed version of Presto, are powerful tools for querying data across various sources like S3 and PostgreSQL. By employing either of these, you can execute SQL queries across your data lake and database without the need to load data into an analytics tool. This approach can significantly reduce the memory footprint of your Metabase instance, as it doesn’t require storing large datasets for querying purposes.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Analytics Postgres Database for Reporting:
&lt;/h3&gt;

&lt;p&gt;Another approach is to set up a pipeline that selectively copies key log events and PostgreSQL data into a dedicated analytics database. This strategy can streamline the data analysis process, particularly for creating an analytics dashboard aimed at end-users. By isolating the analytics data, you can optimize the database schema for reporting and ensure that your production databases are not burdened by heavy analysis queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Exploring Other BI Tools:
&lt;/h3&gt;

&lt;p&gt;While &lt;a href="https://www.metabase.com/" rel="noopener noreferrer"&gt;Metabase&lt;/a&gt; is known for its user-friendliness and simplicity, other Business Intelligence tools like &lt;a href="https://superset.apache.org/" rel="noopener noreferrer"&gt;Superset&lt;/a&gt;, &lt;a href="https://cloud.google.com/looker" rel="noopener noreferrer"&gt;Looker&lt;/a&gt;, or &lt;a href="https://www.tableau.com/" rel="noopener noreferrer"&gt;Tableau&lt;/a&gt; might offer additional features or better integration with existing systems. Each of these tools has its unique strengths — for example, Superset is highly customizable, Looker excels in creating complex data models, and Tableau is renowned for its data visualization capabilities. Depending on the specific needs and existing tech stack of your organization, one of these alternatives might be a more suitable choice.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Utilizing Snowflake, BigQuery, or Redshift:
&lt;/h3&gt;

&lt;p&gt;For more robust data warehousing solutions, &lt;a href="https://www.snowflake.com/en/" rel="noopener noreferrer"&gt;Snowflake&lt;/a&gt;, &lt;a href="https://aws.amazon.com/redshift/" rel="noopener noreferrer"&gt;Redshift&lt;/a&gt;, or &lt;a href="https://cloud.google.com/bigquery" rel="noopener noreferrer"&gt;BigQuery&lt;/a&gt; can be considered. These platforms are designed to handle large volumes of data and complex queries efficiently. They can directly query data stored in S3 and integrate with PostgreSQL, similar to DuckDB. However, they offer additional features like automatic scaling, extensive support for different data formats, and advanced security features. These platforms are particularly beneficial for organizations dealing with massive datasets and requiring a comprehensive data warehousing solution.&lt;/p&gt;

&lt;p&gt;In conclusion, while our implementation with DuckDB and Metabase offers a streamlined and effective solution for our needs, these alternative solutions provide different benefits that could be more aligned with other specific requirements or preferences. The choice of tools and architecture depends greatly on the scale of data, specific use cases, and the existing technical infrastructure of the organization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In wrapping up our journey with DuckDB and Metabase, the key takeaway is the value of simplicity and efficiency in data analysis. Our experience with the MindfulDataAI Search Plugin highlighted how the right tools, like DuckDB and Metabase, can simplify the process of merging different data sources and extracting meaningful insights quickly.&lt;/p&gt;

&lt;p&gt;These tools enabled us to analyze log data and PostgreSQL records effectively, leading to a better understanding of user preferences and improving our services. However, it’s essential to recognize that different scenarios may call for different tools. Alternatives like Presto, Athena, or other BI tools might be more suitable in varying contexts.&lt;/p&gt;

&lt;p&gt;Ultimately, the goal is to choose a solution that is not only effective but also aligns with your project’s specific needs and technical environment. This approach ensures that data analysis remains a practical and valuable asset in decision-making processes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to use ChatGPT in Slack?
&lt;/h2&gt;

&lt;p&gt;At &lt;a href="https://mindfuldataai.com/?utm_source=redgeoff_com&amp;amp;utm_campaign=mpt-7b" rel="noopener noreferrer"&gt;MindfulDataAI.com&lt;/a&gt;, we offer &lt;em&gt;Arty&lt;/em&gt;, an app that integrates ChatGPT with Slack. Arty can be used in group settings or one-on-one, seamlessly incorporating ChatGPT and web search capabilities directly into Slack.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>cloud</category>
      <category>data</category>
      <category>database</category>
    </item>
    <item>
      <title>Running MosaicML's MPT-7B, a ChatGPT Competitor, on AWS SageMaker</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Tue, 18 Jul 2023 15:48:01 +0000</pubDate>
      <link>https://dev.to/redgeoff/running-mosaicmls-mpt-7b-a-chatgpt-competitor-on-aws-sagemaker-4bb5</link>
      <guid>https://dev.to/redgeoff/running-mosaicmls-mpt-7b-a-chatgpt-competitor-on-aws-sagemaker-4bb5</guid>
      <description>&lt;p&gt;In this blog post, I’m going to take you step-by-step through the process of running MosaicML’s ChatGPT competitor, MPT-7B, on your own AWS SageMaker instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx53zblzzw2i441xhk9zs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx53zblzzw2i441xhk9zs.png" alt="MPT-7B and AWS SageMaker" width="800" height="418"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;MPT-7B and AWS SageMaker. Image credit: MosaicML and Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Are you excited about the capabilities of ChatGPT, but have concerns about exposing your sensitive data to OpenAI? Luckily, there are alternatives that you can run on your own infrastructure. One such alternative is MosaicML’s MPT-7b, a competitor to ChatGPT, which we’ll explore in this blog post.&lt;/p&gt;
&lt;h3&gt;
  
  
  Introduction to MosaicML and MPT-7B
&lt;/h3&gt;

&lt;p&gt;MosaicML, recently &lt;a href="https://www.reuters.com/markets/deals/databricks-strikes-13-bln-deal-generative-ai-startup-mosaicml-2023-06-26" rel="noopener noreferrer"&gt;acquired by Databricks for $1.3 billion&lt;/a&gt;, has been making waves in the ML community with their MPT-7B model, a supposed competitor to ChatGPT. Despite its promise, running this model can be daunting due to sparse documentation and its heavy resource requirements. However, one can run MPT-7B on AWS SageMaker in a Jupyter notebook, an environment that is beginner-friendly and highly flexible for rapid iteration. This setup allows you to test the model’s feasibility and hardware requirements before deciding to move into production.&lt;/p&gt;
&lt;h3&gt;
  
  
  Running MPT-7B on AWS SageMaker
&lt;/h3&gt;

&lt;p&gt;Running MPT-7B in a Jupyter notebook on AWS SageMaker provides several benefits. Not only can you pay just for what you use and turn it off when you’re done, but the ability to easily rerun portions of your code without having to reload the model saves time during iterative development. But do beware! If you forget to stop your notebook instances, the charges can quickly add up.&lt;/p&gt;

&lt;p&gt;While this method is relatively convenient, there are some considerations you must take into account. Firstly, loading the model can take up to 20 minutes even on a high-performance GPU, making this process somewhat time-consuming. Also, the cost is a factor to consider, as the running cost is at least $4 per hour. You’ll need to run MPT-7B on at least a &lt;em&gt;p3.2xlarge&lt;/em&gt; instance; anything smaller does not seem feasible. If you opt for EC2 instead of SageMaker, you’ll have to ask AWS for permission to use a &lt;em&gt;p3.2xlarge&lt;/em&gt; instance.&lt;/p&gt;

&lt;p&gt;In the next sections I’ll take you step-by-step through how to run the MPT-7B model in your very own SageMaker jupyter notebook:&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1 - Open the SageMaker Console
&lt;/h4&gt;

&lt;p&gt;Fire up the AWS Console and search for SageMaker:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fypjd8t7bawjo9rh72197.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fypjd8t7bawjo9rh72197.png" alt="Search for SageMaker" width="800" height="242"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Search for SageMaker. Image credit: Author&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2 - Create a notebook instance
&lt;/h4&gt;

&lt;p&gt;From the left-side menu, select &lt;em&gt;Notebook-&amp;gt;Notebook instances&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpkwk8v9bpyo53kaop66m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpkwk8v9bpyo53kaop66m.png" alt="Notebook instances" width="534" height="212"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Notebook instances. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Click the &lt;em&gt;Create notebook instance&lt;/em&gt; button:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7w0kgba0trnkbeki5oyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7w0kgba0trnkbeki5oyw.png" alt="Create notebook instance" width="800" height="190"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Create notebook instance. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Specify an instance name. Choose the instance type &lt;em&gt;m1.p3.2xlarge&lt;/em&gt;. Unfortunately, it seems that an instance as powerful as &lt;em&gt;m1.p3.2xlarge&lt;/em&gt; is required, or else your instance may run out of memory or take an excessive amount of time to respond to even the simplest questions. However, please note that this instance will cost approximately $4/hr, so it’s important to monitor your usage carefully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fccpx9mqp4ibwfobzbpic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fccpx9mqp4ibwfobzbpic.png" alt="Specify notebook instance details" width="800" height="681"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Specify notebook instance details. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Create a new IAM role:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fex0a70yiacms1r136cfl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fex0a70yiacms1r136cfl.png" alt="Create a new role" width="798" height="173"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Create a new role. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If your test environment doesn’t have any particularly sensitive data in it then you can grant access to &lt;em&gt;Any S3 bucket&lt;/em&gt;. Otherwise, you’ll need to be more explicit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxrp80ft2hyjqn5n2si9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxrp80ft2hyjqn5n2si9p.png" alt="Specify S3 access" width="800" height="565"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Specify S3 access. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Click the &lt;em&gt;Create notebook instance&lt;/em&gt; button:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkppv563tfiu275hcas84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkppv563tfiu275hcas84.png" alt="Create notebook instance" width="700" height="248"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Create notebook instance. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The notebook will then be in a &lt;em&gt;Pending&lt;/em&gt; status. This will likely last for about 10 minutes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbsh3mmel8wqi8ssrcd0y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbsh3mmel8wqi8ssrcd0y.png" alt="Pending notebook instance" width="406" height="278"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Pending notebook instance. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the meantime, we’ll download a notebook so that we can upload it after the AWS SageMaker instance has finished provisioning.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 3 - Download the notebook
&lt;/h4&gt;

&lt;p&gt;Head on over to the notebook at &lt;a href="https://colab.research.google.com/drive/1kJr2LHHLKYkbnNutVYEkt2vrYsbO38aw" rel="noopener noreferrer"&gt;MPT-7B on AWS SageMaker.ipynb&lt;/a&gt; and download it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffcjehm82z5n24pkvvdp2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffcjehm82z5n24pkvvdp2.png" alt="The notebook on Google Colab" width="800" height="565"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The notebook on Google Colab. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv3mrvy8qjncu008uvyae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv3mrvy8qjncu008uvyae.png" alt="Download the notebook" width="800" height="801"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Download the notebook. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this notebook you’ll notice two main code blocks. The first block loads the MPT-7B tokenizer and model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bfloat16&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AutoTokenizer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AutoModelForCausalLM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AutoConfig&lt;/span&gt;

&lt;span class="n"&gt;device&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;cuda:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current_device&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cuda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_available&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;cpu&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="n"&gt;tokenizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AutoTokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mosaicml/mpt-7b-chat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;trust_remote_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;init_device&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;meta&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AutoModelForCausalLM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mosaicml/mpt-7b-chat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;trust_remote_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;torch_dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;bfloat16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;device=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;model loaded&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tokenizer is used to encode the question sent to the model and decode the response from the model. Additionally, we obtain the device specification for our GPU so that we can configure the model to utilize it later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;IPython.display&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Markdown&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;StoppingCriteria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;StoppingCriteriaList&lt;/span&gt;

&lt;span class="c1"&gt;# mtp-7b is trained to add "&amp;lt;|endoftext|&amp;gt;" at the end of generations
&lt;/span&gt;&lt;span class="n"&gt;stop_token_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eos_token_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# Define custom stopping criteria object.
# Source: https://github.com/pinecone-io/examples/blob/master/generation/llm-field-guide/mpt-7b/mpt-7b-huggingface-langchain.ipynb
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StopOnTokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;StoppingCriteria&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__call__&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LongTensor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FloatTensor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
 &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;stop_id&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;stop_token_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;stop_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="n"&gt;stopping_criteria&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;StoppingCriteriaList&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nc"&gt;StopOnTokens&lt;/span&gt;&lt;span class="p"&gt;()])&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;ask_question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
 &lt;span class="n"&gt;start_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

 &lt;span class="c1"&gt;# Encode the question
&lt;/span&gt; &lt;span class="n"&gt;input_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_tensors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;pt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

 &lt;span class="c1"&gt;# Use the GPU
&lt;/span&gt; &lt;span class="n"&gt;input_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

 &lt;span class="c1"&gt;# Generate a response
&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;max_new_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;stopping_criteria&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;stopping_criteria&lt;/span&gt;
 &lt;span class="p"&gt;)&lt;/span&gt;

 &lt;span class="c1"&gt;# Decode the response
&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;[:,&lt;/span&gt; &lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]:][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="n"&gt;skip_special_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

 &lt;span class="n"&gt;end_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="n"&gt;duration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;end_time&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt;

 &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Markdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

 &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Function duration:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;seconds&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the use of &lt;code&gt;stopping_critera&lt;/code&gt;, which is needed or else the model will just start babbling on, even after it has answered our question.&lt;/p&gt;

&lt;p&gt;See &lt;a href="https://huggingface.co/transformers/v4.12.5/main_classes/model.html#transformers.generation_utils.GenerationMixin.generate" rel="noopener noreferrer"&gt;model generate parameters&lt;/a&gt; if you want to explore the different options.&lt;/p&gt;

&lt;p&gt;Now, let’s upload this notebook to SageMaker.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4 - Upload the notebook
&lt;/h4&gt;

&lt;p&gt;Hopefully by this time your SageMaker notebook instance has finished being provisioned. When it has, click the &lt;em&gt;Open Jupyter&lt;/em&gt; link:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi3rnxypfp4bbafpg9vxe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi3rnxypfp4bbafpg9vxe.png" alt="Open Jupyter" width="800" height="177"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Open Jupyter. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then, click the &lt;em&gt;Upload&lt;/em&gt; button in the top-right corner of your screen and select the notebook that you just downloaded:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frnm6ruebu5rb4uahob5j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frnm6ruebu5rb4uahob5j.png" alt="Upload the notebook" width="800" height="492"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Upload the notebook. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Set the kernel to &lt;em&gt;conda_python3&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2je00rnot5m7qchhu936.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2je00rnot5m7qchhu936.png" alt="Set the kernel" width="800" height="280"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Set the kernel. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 5 - Run the notebook
&lt;/h4&gt;

&lt;p&gt;Select &lt;em&gt;Cell -&amp;gt; Run All&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffu7x0efhur2nokxx9ggg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffu7x0efhur2nokxx9ggg.png" alt="Run all cells" width="636" height="338"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Run all cells. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An hourglass logo will then appear in the browser tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxo6mf978vogwbyvkv6l6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxo6mf978vogwbyvkv6l6.png" alt="Wait for notebook" width="550" height="130"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Wait for notebook. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You’ll then need to wait about 10 minutes for the model to be downloaded:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftolu0qx1p3elwuyzxym8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftolu0qx1p3elwuyzxym8.png" alt="Download model" width="800" height="205"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Download model. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After it runs, you’ll see the answer to the question &lt;em&gt;Explain to me the difference between nuclear fission and fusion&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbsb3n2yqc0t13v6laxhz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbsb3n2yqc0t13v6laxhz.png" alt="Explain to me the difference between nuclear fission and fusion" width="799" height="176"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Explain to me the difference between nuclear fission and fusion. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since the model and tokenizer have already been loaded above, you can simply modify the &lt;em&gt;ask_question&lt;/em&gt; code block and click the &lt;em&gt;Run&lt;/em&gt; button to ask any other questions. This will save you from spending 10 minutes each time you want to test a new question.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1qo0k90tc4zofsd4utfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1qo0k90tc4zofsd4utfi.png" alt="What is the capital of France?" width="799" height="478"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;What is the capital of France?. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 6 - Stop the notebook
&lt;/h4&gt;

&lt;p&gt;As soon as you have finished testing the model, you’ll want to head back to your list of notebook instances and stop it. If you don’t, $4/hr will add up very quickly 💸&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F52o25l51fauhgit6yf7j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F52o25l51fauhgit6yf7j.png" alt="Stop the notebook" width="798" height="183"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Stop the notebook. Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance Comparison
&lt;/h3&gt;

&lt;p&gt;In terms of performance, my preliminary tests suggest that MPT-7B’s results might not be as good as ChatGPT’s. It does a decent job answering questions like &lt;em&gt;What is the capital of France?&lt;/em&gt;, &lt;em&gt;Explain to me the difference between nuclear fission and fusion&lt;/em&gt;, and &lt;em&gt;Write python code that converts a csv into pdf&lt;/em&gt;. But for questions like_What is the capital of Belize?_ it fails pretty horribly:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdqzqsmurtyyht75d3xbk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdqzqsmurtyyht75d3xbk.png" alt="What is the capital of Belize?" width="797" height="153"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;What is the capital of Belize? Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I am currently collecting more data and will conduct a comprehensive comparative analysis in a follow-up blog post. In that post, I will compare the question and answer performance of MPT-7B, MPT-30B, Falcon-40b, and ChatGPT using actual conversation history.&lt;/p&gt;

&lt;h3&gt;
  
  
  From Testing to Production
&lt;/h3&gt;

&lt;p&gt;Once you’re ready to transition from testing to production, SageMaker offers an additional benefit - the ability to create an endpoint for your model. With SageMaker, you can auto-scale based on demand to the endpoint, optimizing your resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Tips
&lt;/h3&gt;

&lt;p&gt;Be mindful that it’s easy for your process to get forked while running in a Jupyter notebook and run out of memory. If this happens, simply shut down the kernel and run all the commands again.&lt;/p&gt;

&lt;p&gt;If you’re curious about running this model on a platform other than AWS, Google Colab Pro is another viable option at $9/month. However, based on our testing, we found that we exhausted the provided credits within just a few hours. 😳&lt;/p&gt;

&lt;p&gt;Another challenge you may face is the inability to utilize the &lt;a href="https://huggingface.co/mosaicml/mpt-7b#how-to-use" rel="noopener noreferrer"&gt;Triton optimization&lt;/a&gt; on SageMaker due to a CUDA version incompatibility. Unfortunately, AWS’s current P3 instances do not include a recent CUDA version. Therefore, if you wish to utilize the Triton optimization, you will need to create an EC2 container with command line access. However, it’s important to note that you will also require special permission from AWS Support to run an instance with 8 VCPUs. In a future post, I will provide a detailed guide on how to integrate Triton and utilize a more cost-effective GPU cloud provider, such as &lt;a href="//lambdalabs.com"&gt;Lambda Labs&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;While MosaicML’s MPT-7B offers a viable alternative to OpenAI’s ChatGPT, it presents its own set of challenges. Running the model can be time-consuming, expensive, and the available documentation is lacking. However, the ability to keep the model in-house and protect your data from being exposed to OpenAI can be compelling for certain use cases.&lt;/p&gt;

&lt;p&gt;SageMaker offers great convenience for quickly testing the model and provides the flexibility to transition to production when you’re ready. Whether you’re just starting with MPT-7B or have been using it for a while, we hope this guide has provided valuable insights.&lt;/p&gt;

&lt;p&gt;Stay tuned for our next blog post, where we’ll delve deeper into the performance comparisons between MPT-7B, MPT-30B, Falcon-40b, and ChatGPT.&lt;/p&gt;

&lt;p&gt;See the following links if you are interested in learning more about &lt;a href="https://www.mosaicml.com/blog/mpt-7b" rel="noopener noreferrer"&gt;MPT-7B&lt;/a&gt; or its larger variant, &lt;a href="https://www.mosaicml.com/blog/mpt-30b" rel="noopener noreferrer"&gt;MPT-30B&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And remember, whether you’re working with ChatGPT or MPT-7B, the key is to ensure your use case is served without compromising data privacy and cost-effectiveness. Happy tinkering!&lt;/p&gt;

&lt;h3&gt;
  
  
  Want a Turn-Key Solution for Using MPT or ChatGPT with Your Data?
&lt;/h3&gt;

&lt;p&gt;At &lt;a href="https://mindfuldataai.com?utm_source=redgeoff_com&amp;amp;utm_campaign=mpt-7b" rel="noopener noreferrer"&gt;MindfulDataAI.com&lt;/a&gt;, we offer ChatGPT for businesses. If you’re interested in leveraging ChatGPT, MPT, or other models with your company’s data, please get in touch with us.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>llm</category>
      <category>machinelearning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>My Journey with ChatGPT for Business: Unleashing the Power of AI for Software Engineers</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Mon, 10 Jul 2023 13:46:28 +0000</pubDate>
      <link>https://dev.to/redgeoff/my-journey-with-chatgpt-for-business-unleashing-the-power-of-ai-for-software-engineers-1oj</link>
      <guid>https://dev.to/redgeoff/my-journey-with-chatgpt-for-business-unleashing-the-power-of-ai-for-software-engineers-1oj</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;As a software engineer, I'm constantly searching for tools and technologies that can revolutionize the way I work. Today, I want to share a prototype app: ChatGPT for Business. I believe if we follow through on building this, it has the potential to transform our industry. Join me as I take you through my experiences, challenges, and the immense possibilities that lie ahead.&lt;/p&gt;

&lt;h3&gt;
  
  
  From Crypto Trading to AI-Assisted Productivity
&lt;/h3&gt;

&lt;p&gt;The story begins with me leaving my Director of Engineering job at a fast-growing startup that was about to be acquired. I stumbled into the world of crypto trading after attending a web3 event in early 2022, where I heard about arbitrage opportunities. Eager to explore further, I began experimenting with free bots at Pionex and discovered the passive income potential of trading bots. That's when everything changed.&lt;/p&gt;

&lt;p&gt;Driven by curiosity, I reverse-engineered a promising bot, conducted extensive backtesting using historical price data from Binance, and optimized its parameters using genetic mutation techniques. Deploying it on AWS, I witnessed consistent daily returns, achieving a remarkable 18% annual return on a sizable investment. But as the market landscape shifted, I realized that luck played a significant role in my success, and a long-term buy-and-hold strategy would yield better results. When the SEC's lawsuit against Binance and Coinbase loomed, I secured my crypto in wallets and closed my trading operations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Discovering the Power of ChatGPT
&lt;/h3&gt;

&lt;p&gt;During this transformative period, I found myself increasingly relying on ChatGPT, a powerful generative AI model. What began as a tool for trivial questions quickly evolved into something much more. ChatGPT gradually replaced around 80% of my Google searches, becoming indispensable for coding technical analysis algorithms, troubleshooting Docker configurations, proofreading emails, and even generating pitch deck outlines. I realized that ChatGPT had become my go-to resource, surpassing Google searches in many aspects. However, it was missing the capability to search my private data and access any information released after 2021.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Spark of Innovation
&lt;/h3&gt;

&lt;p&gt;One day, over coffee, a friend shared an interesting challenge: scraping information from multiple mom-and-pop websites to create a comprehensive activities-for-kids marketplace. It was at that moment that I had a revelation—what if ChatGPT could help? Instead of writing custom web scrapers for each site, could ChatGPT extract the desired information? Intrigued, I stumbled upon an informative post titled &lt;a href="https://beebom.com/how-train-ai-chatbot-custom-knowledge-base-chatgpt-api" rel="noopener noreferrer"&gt;"How to Train an AI Chatbot With Custom Knowledge Base Using ChatGPT API"&lt;/a&gt;. Inspired by its possibilities, I pointed ChatGPT to a Boys and Girls Club website, asking questions about activities in Seattle, their schedules, and costs. To my delight, the results were remarkably accurate, and the cost of using OpenAI’s API was surprisingly affordable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unlocking the Power of ChatGPT for Business
&lt;/h3&gt;

&lt;p&gt;Fueled by this success, I couldn't help but wonder how I could further enhance my productivity using ChatGPT. To my surprise, I discovered that very few business products allowed users to leverage ChatGPT with their own data. Existing solutions fell short in terms of integrations, customization, and scalability. &lt;a href="https://myaskai.com" rel="noopener noreferrer"&gt;MyAskAI&lt;/a&gt; catered to individuals with one-off files and only allowed two questions per message thread. &lt;a href="https://aisera.com" rel="noopener noreferrer"&gt;AiSera&lt;/a&gt; seemed more focused on building chatbots with custom data. &lt;a href="https://customgpt.ai" rel="noopener noreferrer"&gt;CustomGPT&lt;/a&gt; lacked the necessary integrations with data sources like Google Drive, Salesforce, and Confluence. &lt;a href="https://gerev.ai" rel="noopener noreferrer"&gt;Gerev.ai&lt;/a&gt;, although open-source and appealing, failed to index a 5-page PDF on a brand-new MacBook Pro. &lt;a href="https://klu.so" rel="noopener noreferrer"&gt;Klu&lt;/a&gt; had an impressive turnkey integration with sources like Google Drive, but its "Beta AI" spun endlessly when asked a basic question about a single 5-page PDF file. &lt;/p&gt;

&lt;p&gt;This realization sparked a vision in me—I wanted to build a product specifically designed to empower all businesses, not just the ones with the funds to train new AI models, with ChatGPT's capabilities. Excited by the possibilities, I reached out to my friend Arty, a talented engineer, and we began brainstorming ideas together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Seeking Validation and Refining the Vision
&lt;/h3&gt;

&lt;p&gt;To refine our concept and gain support, we sought guidance from a local venture capitalist (VC). We were told that our idea might be too broad and that we should instead focus on a specific industry. However, we remained unconvinced that there isn't a place for a general-purpose ChatGPT tool for businesses. Therefore, we decided to rely on data to guide us in the right direction. Undeterred, we developed a playbook, crafted surveys, optimized keywords for SEO and advertising, and created compelling website mock-ups. But we knew that true validation would come from our fellow software engineers—the very people who could benefit from ChatGPT for Business—&lt;strong&gt;YOU!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine, if you will…&lt;/p&gt;

&lt;p&gt;A ChatGPT-powered teammate, seamlessly integrated with your data sources and the web, providing real-time insights, securely linked to source documents, and offering turnkey integrations with your company's tools and systems. We envision automated document synchronization, real-time web searches, single sign-on (SSO) integration, access controls, conversation sharing, onboarding and training, and robust security and compliance measures.&lt;/p&gt;

&lt;p&gt;Imagine being able get the status of a Jira ticket in real-time:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhzlerndt899d3joxnnr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhzlerndt899d3joxnnr.png" alt="Ask ChatGPT about a Jira ticket's status" width="800" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or, what about keeping tabs on the competition?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fst1m9tf75qk6e1x1m72p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fst1m9tf75qk6e1x1m72p.png" alt="Ask ChatGPT about a competitor" width="799" height="577"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or, even synthesizing reports from raw data. Sharing and explaining insights (like a goalie, answering questions before you need to!). The more documents you share with the agent, the more time it will save for you as you could even let this AI agent handle basic questions on your behalf!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmp39s3dbbz5urz54x10u.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmp39s3dbbz5urz54x10u.jpg" alt="Soccer goalie by Vidar Nordli-Mathisen" width="799" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The possibilities are endless.&lt;/p&gt;

&lt;h3&gt;
  
  
  Join the Journey
&lt;/h3&gt;

&lt;p&gt;And now, dear reader, we invite you to embark on this incredible journey with us. We think we’re on to something, but we want your thoughts! Your insights and feedback are essential as we shape the future of ChatGPT for Business. Together, we can unleash the potential of ChatGPT, transforming the way we work, and empowering ourselves and our teams with a tool that will revolutionize communication. Please take a moment to share your thoughts by participating in our quick &lt;a href="https://mindfuldataai.com/?utm_campaign=2023_blog_origin_story&amp;amp;utm_source=dev_to" rel="noopener noreferrer"&gt;survey&lt;/a&gt;. Additionally, you can also &lt;a href="https://mindfuldataai.com/survey.html?utm_campaign=2023_blog_origin_story&amp;amp;utm_source=dev_to" rel="noopener noreferrer"&gt;register for the beta release&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Our journey with ChatGPT for Business has been one of passion, innovation, and relentless pursuit. We have witnessed firsthand the immense potential of AI in our field, and we’re determined to harness that power to create a tool that will revolutionize software engineering. Thank you for reading, and we eagerly await your input as we shape the future of ChatGPT for Business together.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>gpt3</category>
      <category>openai</category>
      <category>ai</category>
    </item>
    <item>
      <title>Run a Free VPN Server on AWS (2022 Edition)</title>
      <dc:creator>Geoff Cox</dc:creator>
      <pubDate>Tue, 15 Nov 2022 18:48:50 +0000</pubDate>
      <link>https://dev.to/redgeoff/run-a-free-vpn-server-on-aws-2022-edition-15b3</link>
      <guid>https://dev.to/redgeoff/run-a-free-vpn-server-on-aws-2022-edition-15b3</guid>
      <description>&lt;p&gt;This tutorial will take you through the steps of setting up an EC2 instance running OpenVPN server. It will then cover how to grant and revoke access to your VPN server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fredgeoff.com%2Fposts%2Fvpn-2022%2Fvpn-splash.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fredgeoff.com%2Fposts%2Fvpn-2022%2Fvpn-splash.jpg" alt="Free VPN on AWS" width="799" height="539"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Privecstasy on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;AWS has an awesome firewall built into its core services, which can easily be used to make sure that only certain ports are open to the outside world. One extra step that we can take is to run a VPN server that serves as the gateway to our protected AWS resource, e.g. EC2, RDS, etc… We can then shutdown direct access to our AWS resources just by revoking access via our VPN server. This is very useful if you need to revoke access for a former employee.&lt;/p&gt;

&lt;p&gt;AWS now offers a &lt;a href="https://aws.amazon.com/vpn/" rel="noopener noreferrer"&gt;managed VPN Service&lt;/a&gt;, but this service costs at least $72 a month and is even more expensive when your VPN serves a lot of traffic. A lot of smaller organizations don’t need all the features of the managed service and instead can run their own VPN server for just the cost of an EC2 instance. You can even use the free tier so that you don’t have to pay anything for the EC2 instance for the 1st year.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1 — Create the VPN Security Group
&lt;/h3&gt;

&lt;p&gt;Overview: security groups allow your servers to communicate with each other in a private cloud while exposing specific ports to the world. We are going to create a security group to allow VPN access to our VPN server. We will assume that all your other AWS resources are members of the default security group and that the default security group does not allow access from the outside world.&lt;/p&gt;

&lt;p&gt;Log in at &lt;a href="https://aws.amazon.com" rel="noopener noreferrer"&gt;https://aws.amazon.com&lt;/a&gt;, type &lt;em&gt;EC2&lt;/em&gt; in the search box, and click on the target to go to the EC2 Dashboard.&lt;/p&gt;

&lt;p&gt;From the EC2 dashboard, click &lt;em&gt;Security Groups&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F996um3zmrnel5li9tadt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F996um3zmrnel5li9tadt.png" alt="Security Groups" width="458" height="158"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;em&gt;Create security group&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnnyr9sqxphc6pffyn6gp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnnyr9sqxphc6pffyn6gp.png" alt="Create Security Group" width="799" height="157"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Enter a name and description of &lt;em&gt;vpn&lt;/em&gt; and specify the following inbound rules on ports &lt;em&gt;22&lt;/em&gt;, &lt;em&gt;443&lt;/em&gt;, &lt;em&gt;943&lt;/em&gt;, and &lt;em&gt;1194&lt;/em&gt;. Note: the protocol for port &lt;em&gt;1194&lt;/em&gt; is &lt;strong&gt;UDP&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F37p2377k7x8iluctkax2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F37p2377k7x8iluctkax2.png" alt="Ports" width="800" height="318"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note: if the IP addresses that your team uses are static then you can add yet another layer of security by specifying an IP address range in the &lt;em&gt;Source&lt;/em&gt; of your rules. However, you’ll want to leave the &lt;em&gt;Source&lt;/em&gt; open to anywhere if you want your team to be able to connect from any IP as they may be working from a hotel, home, cafe, etc…&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2 — Create the EC2 Instance
&lt;/h3&gt;

&lt;p&gt;Return to the EC2 Dashboard and then click &lt;em&gt;Launch instances&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2a0nl2xvlf7ahsi9dsyt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2a0nl2xvlf7ahsi9dsyt.png" alt="Launch instances" width="799" height="161"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Select Ubuntu (you can of course select almost any other OS that runs OpenVPN, but this tutorial is tailored to Ubuntu)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F52wsorkvcsy5z5f328v1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F52wsorkvcsy5z5f328v1.png" alt="Ubuntu 22" width="800" height="544"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;em&gt;t2.micro&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1scdg7aybker7kumxwva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1scdg7aybker7kumxwva.png" alt="t2 nano" width="800" height="241"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note: you can use a nano instance instead of a micro instance, but nano instances are not eligible for the free tier.&lt;/p&gt;

&lt;p&gt;In the &lt;em&gt;Network settings&lt;/em&gt; section, select your default VPC and disable the auto-assign public IP option. Then, select both your default security group and the security group that you created above for the VPN.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4uu0kvttf572av6rtq9z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4uu0kvttf572av6rtq9z.png" alt="Edit security groups" width="800" height="663"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;em&gt;Launch instance&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3 — Disable Source/Destination Check
&lt;/h3&gt;

&lt;p&gt;From the list of instances, select the VPN instance and then &lt;em&gt;Actions -&amp;gt; Networking -&amp;gt; Change source/destination check&lt;/em&gt; from the drop down menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc4cheqptt8mclcb9x38d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc4cheqptt8mclcb9x38d.png" alt="Instance source destination check" width="800" height="238"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;em&gt;Stop&lt;/em&gt; and click &lt;em&gt;Save&lt;/em&gt;. This is needed as otherwise, your VPN server will not be able to connect to your other AWS resources.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Falberucpjlz8aewyqpeb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Falberucpjlz8aewyqpeb.png" alt="Edit source destination check" width="800" height="542"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4 — Create an Elastic IP Address
&lt;/h3&gt;

&lt;p&gt;Overview: when an EC2 instance is stopped and restarted, the Public IP address changes. We want the IP address of our VPN server to remain static so we’ll use an Elastic IP Address.&lt;/p&gt;

&lt;p&gt;From the E2C Dashboard, select &lt;em&gt;Elastic IPs&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8gkmq0sugtizxqbwllz3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8gkmq0sugtizxqbwllz3.png" alt="Elastic IPs" width="456" height="204"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;em&gt;Allocate Elastic IP address&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc9x7hd10rur95wegtsld.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc9x7hd10rur95wegtsld.png" alt="Allocate Elastic IP address" width="800" height="314"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Make a note of your new Elastic IP address as this will be the Public IP Address of your VPN server. We will refer to this address later as &lt;em&gt;PUBLIC-IP-OF-VPN-SERVER&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Select the IP address you just created and click &lt;em&gt;Associate Elastic IP address&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxlqgljwc1ughn6vhd5pe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxlqgljwc1ughn6vhd5pe.png" alt="Associate Elastic IP address" width="798" height="241"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then, select the Elastic IP and click &lt;em&gt;Associate address&lt;/em&gt; from the drop down menu.&lt;/p&gt;

&lt;p&gt;Select the EC2 instance you created above and click &lt;em&gt;Associate&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpw0g8qzf1i9xfuqha2gv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpw0g8qzf1i9xfuqha2gv.png" alt="EC2 Elastic IP" width="800" height="560"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 5— Install and Configure the OpenVPN Server
&lt;/h3&gt;

&lt;p&gt;SSH into your VPN server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ssh ubuntu@PUBLIC-IP-OF-VPN-SERVER

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download our helper scripts and set up a default config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/redgeoff/openvpn-server-vagrant
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;openvpn-server-vagrant
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cp &lt;/span&gt;config-default.sh config.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit config.sh and enter in your configuration. Note: &lt;em&gt;PUBLIC_IP&lt;/em&gt; should be equal to the Elastic IP Address that you created above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;nano config.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch to root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;su -

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll now update Ubuntu. Note: you will be prompted several times and when you do, just press the &lt;em&gt;Enter&lt;/em&gt; key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;/home/ubuntu/openvpn-server-vagrant/ubuntu.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, install OpenVPN. Note: you will be prompted several times and when you do, just press the &lt;em&gt;Enter&lt;/em&gt; key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;/home/ubuntu/openvpn-server-vagrant/openvpn.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, the OpenVPN server is running.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6 — Add the Route
&lt;/h3&gt;

&lt;p&gt;Routes must be added to the server so that your team’s clients know which traffic to route to the VPN server.&lt;/p&gt;

&lt;p&gt;You can determine the proper subnet by returning to your list of EC2 instances, clicking on a target instance and identifying the Private IP.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffmgntow460yvc0vv2siw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffmgntow460yvc0vv2siw.png" alt="Identify Private IP" width="799" height="182"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Your network will be the first 2 parts of the Private IP appended with zeros, e.g. &lt;em&gt;172.31.0.0&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On the VPN server edit &lt;em&gt;/etc/openvpn/server/server.conf&lt;/em&gt; and add something like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cisco_ios"&gt;&lt;code&gt;&lt;span class="k"&gt;push&lt;/span&gt; "route &lt;span class="m"&gt;172.31.0.0&lt;/span&gt; &lt;span class="m"&gt;255.255.0.0&lt;/span&gt;"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, restart the VPN server with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;systemctl restart openvpn-server@server.service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 7 — Grant Access to Your VPN
&lt;/h3&gt;

&lt;p&gt;Note: We assume that you are still SSH’d into the VPN and logged in as root.&lt;/p&gt;

&lt;p&gt;Run the following command and be sure to replace &lt;em&gt;client&lt;/em&gt; below with a unique name for your user/client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;/home/ubuntu/openvpn-server-vagrant/add-client.sh client

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll then find a configuration file at&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/client-configs/files/client-name.ovpn

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will want to provide this file to the individual on your team who will be connecting to your VPN. SCP is handy for downloading this .ovpn file from your VPN server.&lt;/p&gt;

&lt;p&gt;Your team can use one of various VPN clients such as &lt;a href="https://tunnelblick.net/" rel="noopener noreferrer"&gt;Tunnelblick&lt;/a&gt; (OS X) and &lt;a href="https://openvpn.net/community-downloads/" rel="noopener noreferrer"&gt;OpenVPN&lt;/a&gt; (Linux, iOS, Android and Windows). After installing one of these clients, they should be able to set up the VPN config just by double clicking on the .ovpn file.&lt;/p&gt;

&lt;p&gt;Note: once connected to the VPN, your users will want to use the Private IPs of your AWS resources. You may want to use &lt;em&gt;nslookup&lt;/em&gt; to lookup the IP address from the AWS custom domain names provided by AWS. You’ll probably want to use Route 53 to create subdomain records that route to the Private IPs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 8 — Revoke Access to Your VPN
&lt;/h3&gt;

&lt;p&gt;Note: We assume that you are still SSH’d into the VPN and logged in as root.&lt;/p&gt;

&lt;p&gt;Run the following command and be sure to replace &lt;em&gt;client&lt;/em&gt; below with a unique name for your user/client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;/home/ubuntu/openvpn-server-vagrant/revoke-full.sh client

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Troubleshooting
&lt;/h3&gt;

&lt;p&gt;If your VPN client reports a &lt;em&gt;TLS handshake failed&lt;/em&gt; error then this is most likely because your VPN security group (Step 1) is incorrect. Make sure that you have the correct ports and protocols specified — a common problem is not specifying UDP for port 1194.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>networking</category>
      <category>security</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
