game_revenue = pb.load_dataset(dataset="game_revenue", tbl_type="polars")The features in this chapter need the generation extras, installed with pip install "pointblank[generate]", and an API key for a model provider. A book render cannot reach a provider, so the calls below are marked #| eval: false and are not run. DraftValidation and EditValidation are also marked experimental in the library, so their interfaces may change.
The previous chapter used a language model to judge data. This chapter uses one to help write the validation plan. When you are faced with an unfamiliar table with dozens of columns, the hardest part is often getting started and deciding which checks are worth writing. Pointblank can take a first pass at this for you. It can draft a plan from scratch, revise an existing plan based on an instruction, or suggest what a plan is missing. In every case you review the proposal before anything is accepted.
It helps to know up front what the model is sent. It does not get the full table. Instead, Pointblank sends a DataScan profile, the same kind of summary described in Chapter 3. The profile includes the row count, the column names and types, summary statistics for each column (such as the number of missing values, the minimum, and the maximum), and a short sample of five values from each column. So a small amount of real data does leave your machine, which matters if some columns are sensitive. We use game_revenue for the examples.
The most common starting point is asking the model to draft a plan.
18.1 Drafting a plan with DraftValidation
The DraftValidation class profiles a table and asks a model to propose a complete validation plan for it. You create it with the data and a model name, and displaying the result shows a pb.Validate(...) chain that you can copy into your code and edit.
pb.DraftValidation(data=game_revenue, model="anthropic:claude-sonnet-5")The draft comes back as Python code. A typical draft checks the schema, checks the identifier columns for nulls, limits the numeric columns to the ranges seen in the profile, and limits columns with few distinct values to the values seen in the profile. It is a starting point, not a finished plan. The model knows what the data looks like right now, but not what your business rules require, so you edit the draft to match your intent, such as replacing an observed range with a real limit or removing a check that does not matter. The generated code is available as the object’s code attribute, and the validate_syntax() method checks that it parses before you run it.
When reviewing a draft, pay the most attention to the ranges and sets. A drafted check describes what the data currently is, not what it should be. The largest item_revenue in game_revenue is 142.99, so a draft might propose that the column stays below 150. That describes the current data, but it will fail the first time a legitimate larger purchase comes in. Treat each drafted range as a question: is this a real limit, or just the range the model happened to see? Where the two differ, replace the observed number with the one you actually intend. The model cannot make this call for you, which is why a draft is only a first pass.
A drafted check reflects what the data happens to contain, not what your business rules require. Check every generated range and set, and replace observed values with intended ones before accepting it. Otherwise a check that only describes today’s data will fail on tomorrow’s normal data.
18.2 Editing a plan with EditValidation
Once you have a plan, EditValidation revises it based on a plain-language instruction. This is useful when you know what change you want but would rather describe it than edit the code by hand. You give it the plan, an instruction, and a model, and optionally the data so the model can take the table’s actual columns and values into account. We start with a small plan written by hand.
base = (
pb.Validate(data=game_revenue, tbl_name="game_revenue")
.col_vals_gt(columns="session_duration", value=0)
.col_vals_not_null(columns="player_id")
)That is an ordinary Validate object. Asking for a change gives you a proposal, not a modified plan, and you look at the proposal before accepting it.
edit = pb.EditValidation(
validation=base,
instruction="Also require item_revenue to be non-negative and item_type to be one of iap or ad.",
model="anthropic:claude-sonnet-5",
data=game_revenue,
)
print(edit.diff())The diff() method shows the change as a text diff. The changed_steps() method lists the changes as structured records of added, removed, and modified steps, and review() shows the change as a table. When you are happy with it, accept() runs the revised code and returns a new Validate object that you can interrogate.
revised = edit.accept()
revised.interrogate()Nothing changes until you call accept(). You can also start from a plan stored as a code string, a YAML string, or a file path instead of a Validate object, so EditValidation works just as well with plans kept in version control as with plans in a notebook.
18.4 Suggesting improvements
The suggest_improvements() method starts from a plan you already have and proposes what it is missing. It profiles the table, looks for gaps, such as columns that no step checks or steps that could use thresholds, and returns an EditValidation with the proposed additions for you to review.
proposal = base.suggest_improvements(model="anthropic:claude-sonnet-5")
print(proposal.diff())
improved = proposal.accept()Use this to fill out a plan that works but may not be thorough. It is easy to miss gaps when you write checks one at a time. As with the other tools here, the additions only take effect once you accept them.
18.5 The interactive assistant
For exploratory work, the assistant() function opens a chat session about a table. You can ask what checks make sense, ask for a plan, or refine one over several messages rather than with a single instruction.
pb.assistant(model="anthropic:claude-sonnet-5", data=game_revenue, tbl_name="game_revenue")The assistant is most useful when you are first getting to know a dataset and are still working out what to check. It works alongside the exploration tools of Chapter 3.
18.6 Choosing and combining the tools
Which tool to use depends on where you are starting. If you have an unfamiliar table and no plan, DraftValidation is the fastest way to get a draft, and assistant() suits the same situation if you would rather work through it in a conversation. If you know what you want to check but have no plan yet, from_prompt() turns your description into steps. If you already have a plan and want a specific change, EditValidation makes it from an instruction. And if you want to know what a working plan is missing, suggest_improvements() proposes additions.
The tools also work well in sequence. For example, you might draft a plan with DraftValidation, refine it with one or two EditValidation instructions, fill gaps with suggest_improvements(), and, after reviewing and accepting each proposal, export the finished plan with to_yaml() so it can be kept in version control (see Chapter 20). Since the edit tools accept a YAML string or file path, you can pick that stored plan up and revise it later the same way. The model speeds up each step, but the plan that ends up in the repository is one a person reviewed and accepted. Keep in mind that DraftValidation and EditValidation are experimental, and model output is not deterministic, so two drafts of the same table can differ. That is one more reason to review everything.
18.7 What the model sees, and what it cannot write back
There are two limits to keep in mind across all of these features. The first is what the model is sent. It gets the DataScan profile described at the start of this chapter: summary statistics plus a five-value sample from each column. The rest of the table stays on your machine, but those sample values do not. If a column holds personal or confidential information, its sample values will be included in the request. For sensitive data, consider a local model through "ollama", or write the plan by hand.
The second limit comes from how the edit tools work, which is by converting the plan to to_code() text and back. As described in Chapter 12, that text form cannot represent everything. When a plan goes through the AI tools, the expressions in col_vals_expr(), conjointly(), and specially() become placeholders, pre= functions and step actions= are dropped, a callable active= becomes True, and col_vals_in_table() steps are left out. Pointblank warns you when this happens. Plans built from the other built-in checks come through unchanged, but plans that rely on custom Python logic need that logic added back by hand after an edit.
18.8 Summary
AI-assisted authoring helps you write validation plans without starting from nothing, while leaving the final decision to you. DraftValidation proposes a complete plan from a table’s profile, EditValidation revises a plan from a plain-language instruction, from_prompt() builds a plan from a description, and suggest_improvements() proposes additions to an existing plan. The edit-based tools return a proposal that you inspect with diff(), changed_steps(), or review() and apply with accept(), so nothing changes without your approval. The assistant() function offers a conversational way to explore what a table needs.
In all cases, the model works from a DataScan profile with summary statistics and a small sample of values from each column, not the full table. The edit tools share the export limits described in Chapter 12, so custom Python logic has to be added back after an edit. The next part covers the practical setup around validation, starting with Chapter 19 and the kinds of data Pointblank can validate.