Using AI agents with the Simple Data Analysis library
Last updated on
Many AI agents now write code better and faster than we do. You’re still the one responsible for your findings (and probably will be for a very long time 😁), so you need to be able to double-check the agent’s work.
If you’ve worked through a few of my lessons, you’ll know I like a question-driven approach to data analysis. I think starting with a clear-cut question is the most efficient way to pin down what we want to find out, what we need to measure, and how to interpret the results.
I created the setup-data-project skill to help you and your agent work the same way. It sets up a new data project and gives the agent instructions based on the practices I follow in my own work. The goal is to make the analysis easy to review and the findings easy to understand and explain.
In this lesson, I’ll show you how to use the skill with traffic collisions data from the Toronto Open Data Portal. We’ll find questions the data can answer, process the data efficiently, and share the findings on a web page with interactive charts and an interactive map.
Install the skill
A skill is a set of instructions you can give your coding agent for a recurring task. With setup-data-project, you can ask the agent to prepare a TypeScript project with the Simple Data Analysis library (give it a star on GitHub ⭐).
Your agent can install the skill itself. Copy and paste the message below into its chat to make the skill available in all your projects.
Install the setup-data-project skill globally from this GitHub folder.
https://github.com/nshiab/setup-data-project/tree/main/skills/setup-data-projectYou can also install it from the terminal if you prefer. Run this command (Node.js 22.20 or later) and select your coding agent when prompted.
npx skills add nshiab/setup-data-project --skill setup-data-project --globalFor a manual installation, copy the skill folder from GitHub into the folder where your agent keeps its skills.
Invoke the skill
Once the skill is installed, you may need to relaunch your coding agent so it can find the skill. Then open the folder you want to work in. Use your agent’s skill menu or chat syntax to invoke it. The examples here use /setup-data-project. Your agent may use a different syntax, such as @setup-data-project.
To try the skill, download Traffic Collisions - 4326.csv from the Toronto Open Data Portal’s Traffic Collisions dataset . Drag the CSV into your agent’s chat and send this prompt.
/setup-data-project Help me analyze this data.Depending on which AI agent you use, it should look roughly like this.

From there, your agent will run the setup-data-project library to create the project files and folders and install the simple-data-analysis library. It will then copy the CSV into your project’s sda/data/ folder, tell you where it saved the file, and start looking at the data.
Once the project is set up, the agent will organize the work into three steps.
- Methodology. Confirm where the data comes from, review its documentation, and agree on focused research questions.
- Data processing. Prepare the data, run the analysis, and verify the results.
- Presentation. Share the findings in the format you prefer.
In the reply below, the agent starts with methodology by asking me a few questions about the data.

As the agent probably mentioned in its first reply, it copied the traffic collisions CSV into your project. Open the project in VS Code or any editor you prefer. You can also browse the files from your agent if it has a file browser. You’ll see how the setup-data-project library organized the project (see the setup lesson for details). The CSV is in sda/data/.
Two other files are worth opening. The agent created methodology/methodology.md to keep track of decisions as the analysis progresses. If you start a new chat in the same project, the agent can read that file and pick up where you left off. The sda/main.ts file is the entry point for the analysis. That’s where the agent will write the code that runs the data processing.

If you just want to set up a new project, you can send /setup-data-project on its own.
To see exactly what the setup creates, explore the project folder yourself or read the setup lesson, which walks through the files and folders in detail.
1. Methodology
Before writing any code, you need to understand your data and know what you’re looking for. The agent starts by helping you do three things.
- Understand what the data covers.
- Define the questions that will guide your analysis.
- Identify the indicators you’ll use to answer those questions.
The data
The agent first tries to understand the data in your project. As we saw above, it starts by asking where the dataset came from, who published it, and what documentation is available. The Toronto Open Data Portal page has the information the agent asked for, so I sent it the link.
If you’re following along, send the same reply to your agent.
This data comes from here:
https://open.toronto.ca/dataset/police-annual-statistical-report-traffic-collisions/Share a link to the data source whenever you can. The agent can visit the page, look for context and documentation, and offer to save useful files with the project.
Here, the agent found the Toronto Police Service’s official documentation PDF and offered to download it to sda/data/. It gave me three options, A, B, and C. I’ll type A and press Enter to accept the summary and download the PDF.
Supporting documentation found
The Toronto Open Data page links to Toronto Police Service’s official documentation PDF:
PSDP_Open_Data_Documentation.pdf(~722 KB). Downloading a copy intosda/data/could clarify official definitions, whatNSAandN/Rmean, coordinate-offset rules, and any known reporting caveats.Please let me know if anything in the dataset summary needs correcting or extra context.
Methodology: Does this summary match your understanding of the dataset, and would you like me to download
PSDP_Open_Data_Documentation.pdfintosda/data/before we define your research questions?
- A [Recommended] – Yes, the summary looks right, and download the official documentation PDF into
sda/data/.- B – Yes, the summary looks right, and skip downloading the PDF — let’s move straight to research questions.
- C – Let me clarify or add context about the dataset first.
To keep things clear and efficient, the agent will put the current step in bold, then ask its question. It will label suggested answers with letters like A, B, and C so you can reply with a single letter. 🏃
The questions
Once you and the agent have a shared understanding of the data, the next step is to identify clear questions to guide the analysis. If you’re still exploring, the agent can suggest a few angles. If you already have a topic in mind, it can help you turn it into focused questions. It may also suggest splitting a complicated question into smaller ones so the analysis is easier to follow and review.
Below, you can see what the agent suggested. Option B, Vulnerable road users, sounds interesting, so I’ll type B and press Enter to choose it. Of course, you can always send the agent a message about a different topic that interests you.
Methodology: What would you like to investigate in Toronto’s traffic collisions data?
- A – Long-term and post-pandemic trends: How have total collisions, injury collisions, and fatalities changed from 2014 to 2025 (and how does the first half of 2026 compare)?
- B – Vulnerable road users: How have collisions involving pedestrians, cyclists, and motorcyclists changed over time, and how often do they result in injury or death compared with other collisions?
- C – When collisions happen: Which months, days of the week, and hours of the day see the most collisions, injuries, fatalities, and fail-to-remain (hit-and-run) incidents?
- D – Where collisions concentrate: Which Toronto neighbourhoods and intersections have the highest numbers of collisions, injuries, or fatalities (among mapped collisions)?
- E – A broad overview combining trends, vulnerable road users, timing, and locations (broken into 3–4 focused questions).
- F – Something else — tell me the specific question(s) you have in mind.
After I chose vulnerable road users, the agent looked at the data and documentation to figure out which questions we could answer about this topic. It started by explaining the limitations of the data. I’m sharing the end of its reply here to focus on the questions it proposed.
Option B makes the most sense to me because it keeps the analysis focused on complete years, from 2014 to 2025.
To keep the investigation clear and focused, I suggest breaking your topic into two core research questions:
- Question 1: How have annual collisions involving pedestrians, cyclists, and motorcyclists changed in Toronto from 2014 to 2025?
- Question 2: How often do collisions involving pedestrians, cyclists, and motorcyclists result in injury or death compared with other motor vehicle collisions, and what share of Toronto’s fatal collisions involve them?
Methodology: How would you like to scope the research questions?
- A [Recommended] - Use these 2 core questions (2014–2025 full years, plus a Jan–Jun 2014–2026 check for 2026).
- B - Use these 2 core questions for 2014–2025 only (exclude partial 2026).
- C - Use these 2 core questions and add a 3rd question on when and where vulnerable road-user collisions happen most (season/time of day and neighbourhoods).
- D - Use these 2 core questions and add a 3rd question on fail-to-remain (hit-and-run) collisions involving vulnerable road users.
- E - Something else — tell me the exact questions you want to focus on.
The indicators
Now that we have two clear questions, we need to decide what to measure in the data to answer them. I call these measures indicators. The agent uses the data and supporting documentation to propose indicators (and flag their limitations) for each question.
The agent also explained how it would count collisions involving more than one road-user group. A collision counts once in each group it involves and once in the combined total. The agent reports collisions with unknown road-user groups separately and calculates the percentages using only the records with known groups. Here’s an excerpt from the agent’s reply.
Question 1: How have annual collisions involving pedestrians, cyclists, and motorcyclists changed in Toronto from 2014 to 2025?
- Indicators: Annual collision counts by road-user group (2014–2025); annual share of known-group collisions involving vulnerable road users; percentage changes (2014–2025 and 2019–2025); and annual injury-or-fatal and fatal collision counts for each vulnerable road-user group.
- Limitations: No trip or distance exposure data (so changes in counts cannot separate travel volume from risk per trip);
N/Rroad-user rows spike in 2018 (2,171) and 2019 (1,358), which may slightly understate group counts in those two years.Question 2: How often do collisions involving pedestrians, cyclists, and motorcyclists result in injury or death compared with other motor vehicle collisions, and what share of Toronto’s fatal collisions involve them?
- Indicators: Injury-or-fatal collision rate (%) and fatal collision rate (%) by road-user group (2014–2025); total fatalities associated with each group; each group’s share of all collisions vs. its share of injury-or-fatal and fatal collisions; and relative rate multiples vs. other motor vehicle collisions.
- Limitations: Occurrence-level data shows road-user involvement, not which specific person was injured or killed (Toronto Police’s separate Killed or Seriously Injured dataset tracks person-level victim roles if you ever want to add it);
INJURY_COLLISIONSdoes not distinguish injury severity or count injured people; minor non-injury pedestrian/cyclist incidents are likely underreported compared with automobile property-damage collisions, which can push up the observed injury rate among reported vulnerable road-user collisions.Methodology: Does this plan (indicators, rules for overlapping/unknown records, and limitations) look good so I can record it in
methodology.mdand move to Data processing?
- A [Recommended] - Yes, approve this methodology and start Data processing.
- B - Approve the two questions, and also search the web / Toronto Open Data for additional context (such as Toronto Police’s KSI dataset or published road-safety reports) before moving on.
- C - Let’s adjust the indicators, definitions, or rules first — tell me what you’d like changed.
I’m happy with the proposed indicators, so I’ll reply A to approve the methodology and move on to data processing.
Once I approve the methodology, the agent automatically updates methodology.md with our decisions. If I start a new chat in the same project, even with a different agent or model, it can read the file to see exactly what I’ve approved and pick up where I left off. I can also use the file to review the plan and double-check our decisions. Open methodology.md in your project to see how much we’ve already gathered. 🔎
2. Data processing
Once you and the agent agree on the research questions and how to answer them, the agent starts writing code. It organizes the code the way I like to write my own. The main script, sda/main.ts, uses comments to show which question each section addresses. It calls functions in sda/helpers/ for tasks like preparing the data and calculating the indicators.
The agent aims to keep the code easy to read and review. It prioritizes the Simple Data Analysis methods we’ve used in the lessons on tabular data, geospatial data, and visualizing data. Open a few of the helpers in your project. If you’ve followed those lessons, you should be able to skim the code and get a quick sense of what the agent is doing.

With the code organized by research question and split into helper functions, you can follow the analysis and review it line by line if you need to. You’ll also see a sda/test/ folder. The agent mirrors the organization of the code there so you can tell which test goes with which file. For example, in my project, sda/helpers/classifyCollisions.ts has a corresponding test at sda/test/helpers/classifyCollisions.test.ts.
These tests help catch bugs during the analysis. They also help you check that the existing code still works if you change the focus, add a question, or explore a new topic.
Once the code runs successfully, the agent shares its findings and explains the limitations in the chat. That can be a lot to read in a chat interface. At the end of its reply, the agent should ask if you’re happy with the findings and ready to move on to the next step, presentation. That’s where you can ask the agent to share the results in a format that’s more enjoyable to explore.
For example, here’s what the agent asks me after sharing all the findings and explaining their limitations. I’ll reply A to move on to presentation.
Data processing: Do these findings and caveats look accurate and complete, or would you like to adjust anything before we move on to Presentation?
- A [Recommended] - The findings look good — let’s commit this milestone and move on to Presentation.
- B - I’d like to explore a follow-up check or adjust the analysis first — tell me what to check.
By the way, the agent automatically adds all the findings and any new limitations to methodology.md, where it keeps track of its work. Take another look to see how the analysis has evolved.
You should now see a Summary of findings section near the top of the file. Scroll down and you’ll find a Findings subsection under each research question with the results of our calculations.

3. Presentation
We’ve agreed on the methodology, run the analysis, and now have our findings. The next step is to decide how to present them. Here’s what the agent suggests.
Presentation: How would you like to present the findings?
- A - Terminal output: Answers and tables printed in the terminal, with optional static charts saved in
sda/output/.- B - Markdown document: Findings in
methodology.mdwith embedded static charts and tables.- C - Website: A web page, dashboard, or interactive visualization built in
src/site/.- D - Other: Another format you have in mind — tell me what you’d prefer.
Depending on what you need, seeing the answers and tables in the terminal might be enough. You could also keep the findings in methodology.md and add a few charts and tables. Or you could ask the agent to present the findings on a web page.
That’s what I’ll ask for in this example by replying C. A well-organized web page can make the main findings easier to take in. It can also give readers a way to explore the data themselves. For example, a chart with filters, buttons, or drop-down menus can let them focus on a particular group or time period.
When you ask for a website, the agent starts by checking methodology.md and using it to plan the page. It asks you to review the layout so you can suggest changes or approve it. For example, here’s the layout the agent suggested for the web page I requested.
Before building the site in
src/site/, here is the proposed single-page layout adapted frommethodology.md:
- Page header: Title, author (and optional contact details), linked data source and documentation, last updated timestamp, and AI models used (
Gemini 4 Neon).- Summary of findings: Plain-language takeaways and headline numbers from both research questions.
- Data preparation: Brief overview of the shared 2014–2025 cleaning rules (excluding partial 2026, combining injury and fatal flags, and handling overlapping and unknown road-user records).
- Question 1: How have annual collisions involving pedestrians, cyclists, and motorcyclists changed in Toronto from 2014 to 2025?
- Short answer and supporting evidence.
- Responsive Observable Plot line chart (2014–2025) + sortable annual and period-change tables.
- Collapsed-by-default Methodology panel (indicators, method, and limitations).
- Question 2: How often do collisions involving pedestrians, cyclists, and motorcyclists result in injury or death compared with other motor vehicle collisions, and what share of Toronto’s fatal collisions involve them?
- Short answer and supporting evidence.
- Responsive Observable Plot comparison chart(s) + sortable severity table (including unknown road-user rows).
- Collapsed-by-default Methodology panel (indicators, method, and limitations).
- Footer: Project credits for
setup-data-projectandsimple-data-analysis.
The layout looks good to me, so I approve it. Next, the agent asks who should be credited as the author of the analysis so it can add a byline to the page. You can give it your name and any other details you’d like to include.
After you share your byline details, the agent starts building the page. It runs a local server and opens a live preview so you can watch the page take shape. Here’s what my preview looked like at the start.

A few minutes later, I had a complete website. The page opens with an introduction, followed by a summary of findings and a section for each research question. You can scan the main findings, then use the interactive charts to dig into the results for each question.
Just by scanning the summary of findings, I can already see two striking patterns this workflow helped me uncover.
- Cyclist collisions grew while pedestrian and motorcyclist collisions fell.
- Among records with known road-user groups, vulnerable road users were involved in 4.7% of all collisions and 74.1% of fatal collisions.

Because we’re on a web page, the agent can make the charts interactive. In the chart for Question 1, I can choose which collisions to count and which road-user groups to show. For example, I can focus on fatal collisions involving cyclists or compare trends across all three groups.

Once the page is built, you can keep refining your analysis. For example, the Toronto dataset includes geographic coordinates, so I asked my agent whether we could put them to use.
I'm wondering if there's an opportunity to create an interactive mapThe agent suggested adding a third research question.
Question 3: Where in Toronto do vulnerable road-user collisions and fatal collisions concentrate (2014–2025)?
I agreed, and we went back and forth a bit about which indicators to use and how to account for the data’s limitations. A few minutes later, the agent had added a new section with an interactive map, recorded the addition in methodology.md, and written new functions in sda/helpers/ that I can open and review as needed.

Another benefit of the setup-data-project skill is that it guides the agent to build a static website in src/site/. The charts and filters run in the browser, so the host only needs to serve the files. You can publish the site easily and at low cost by uploading the folder’s contents to a static host, as I’ve done here. Follow the link below to try it yourself.
Explore the interactive Toronto traffic collisions report
You can also zip the src/site/ folder and send it to a colleague. They can unzip it and double-click index.html to open the report directly in their browser without running a local server. The map needs an internet connection to load its mapping library and basemap.
Conclusion
And there you go! We started with a CSV file and ended up with an interactive report. 📊
AI agents can do a lot. Without clear instructions, you can spend a lot of time figuring out what they did and whether their findings are accurate. That’s why I built the setup-data-project skill. It helps the agent and me stay focused on the same research questions and gives me a record I can check as we work together.
It’s tempting to jump straight into coding when you start a new analysis. Agents have the same tendency. The skill makes you take a minute to think about which questions you actually want to answer. That helps you focus on the data you need and spend less time sifting through the rest.
If you’re wondering how the agent knows to guide you through this question-driven workflow, open AGENTS.md at the root of your project. That’s where the agent gets its instructions for the analysis. Feel free to edit them to suit the way you work. If you have ideas for improving the workflow, I’d love to hear from you. You can reach me through the contact page.
If you haven’t tried the other lessons in this chapter, start with Setup, then dive into Tabular data, Geospatial data, and Visualizing data. You’ll set up a project with setup-data-project (the library the skill uses) and get to try simple-data-analysis, the library I maintain. It’s easy to use, it’s fast, and it’s worth a try!
Have fun! 🤖