Course lesson 30 · Building AI Workflows

Saving AI output in our DB

One study unit · Read, recall, then practice · Original video 00:09:20

This lesson connects the AI classification to persistent application data. Sampled video frames show a database-save workflow step, shared evaluation queries, and a fix that initializes the database inside the workflow entrypoint. The final D1 Studio frame shows an evaluation saved with UNKNOWN_STATUS, preserving uncertainty instead of silently treating it as an available product. This summary covers visible implementation; the narration was unavailable.

Primary source: course video 30 · Sampled video frames; narration unavailable · 00:09:20.

Understand the idea

What the course does

  1. Add a named database-save step after the AI classification and pass the workflow payload identifiers plus the model's status and reason.
  2. Implement addEvaluation in the shared data-ops package, insert into destinationEvaluations, and return the ID.
  3. Add account-filtered read helpers for unavailable evaluations and evaluation history, then rebuild the shared package for the consuming service.
  4. Inspect the deployed workflow's failed save step and the database initialization code; add initialization at the start of the workflow run method.
  5. Check the completed step history and query destination_evaluations in D1 Studio to verify the saved record.

Watch for

Follow the final workflow correction in lesson 34 when combining these steps.

Recall before revealing

Why might the workflow fail to save when the ordinary Worker already initializes the database?

Reveal the explanation

The workflow has its own entrypoint and execution path. Its database helper must be initialized with the binding available to that path; initialization in another entrypoint cannot be assumed.

Try it

Sketch the fields in a saved evaluation and mark which come from the workflow payload and which come from the AI result. Add where database initialization occurs.

Check your result

Link/account/destination identifiers come from the payload, status/reason come from the model result, and the workflow initializes its database access before querying.

Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.

Rewatch only what you need

Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.

Companion primary documentation: Drizzle with Cloudflare D1. For recorded API names, commands, limits, and prices, check the version you use.

← Previous   Next →