Basis Lab

Models That Use Tools

Checking What the Model Asked For

Last timeDescribing a Tool Well

The program should treat a requested call the way it treats a form submitted by a stranger: check the shape, the values and the permission, and refuse in a way the model can recover from.

A requested call is untrusted input

A web application receiving a form from the public internet validates every field, and nobody argues about it. The call a model requests deserves exactly the same treatment, for two separate reasons.

The first is that the model is unreliable. Not malicious, just wrong sometimes, in the ways the previous lesson described: an amount in the wrong units, an identifier in the wrong format, a value outside the allowed set.

The second is more serious. The text the model produced may have been influenced by content the system fetched earlier, which is the subject of the seventh lesson. A request that arrives at the program carries no evidence of where its contents came from, which means it cannot be given any standing at all.

FIG 1How much of a form check applies to a requested call
applies to a web formapplies to a model callusually writtencost to write
does the field exist1111
is it the right type1111
is it in the allowed range1101
is the caller permitted1102
is it the right shape of identifier1101
is the action rate limited1102
Coded 1 for yes and 0 for no, with cost on a scale of one to three. The second column is identical to the first, which is the point of the figure, and the third column is where most systems actually are: the mechanical checks get written because they fail loudly, and the four that matter get skipped because omitting them produces something that works in testing. The cost column shows that none of them is expensive.

The four checks

In order, because the order matters for what the error message can say.

Does the tool exist. A model will occasionally request a tool that is not in the list, often one that would be reasonable to have, and the rejection should name the tools that do exist.

Is the request well formed. The right values present, of the right types, identifiers matching their expected shape. This is schema work and it should be generated from the same definition the description was generated from, so the two cannot drift apart.

Are the values allowed. A refund not exceeding the order total. A date range not longer than a year. A row count within the limit. This is where business rules live and it is the check most often absent, because the rules are known to the people who built the tool and were never written down anywhere a program could read.

Is the caller permitted. Not whether the model is permitted, which is a meaningless question, but whether the person on whose behalf the system is acting may do this to this record. A system that holds broad credentials and acts for a specific user has to apply that user permissions itself, because nothing else will.

FIG 2How much the checks have to catch, on a system making five thousand calls a day
stepthe quantitywhere it comes fromthe numberwhat happened
1calls the system requests in a daycounted in the logs5,000The one quantity every system of this kind already knows, usually without anybody having looked.
2the share of them bad in some waya sample of them read by a person6 per centWrong units, wrong identifier format, a value outside the allowed set. Not malice and not rare.
3so bad calls produced in a day5,000 at 6 per cent300This row is produced whatever is done about it. Validation changes how many arrive at a tool, not how many are asked for.
4bad calls you will tolerate reaching a toola decision somebody makes, not a measurement30The only row that is a choice. Write it down, because every argument about how much checking is enough is really an argument about this number.
5so the share validation must catch1 minus 30 in 30090 per centAchievable with the four mechanical checks above, which is the useful finding: the target is demanding and the means are cheap.
6and with no validation at allall 300 arrive300 a day, one every five minutesA day has 1,440 minutes. A system with nothing in front of its tools is not occasionally wrong, it is wrong on a schedule.
7if the tolerance were 3 rather than 301 minus 3 in 30099 per centA tenth of the tolerance is nine more points to catch, and the last nine points of anything are a different undertaking from the first ninety.
7 steps
Only the first, second and fourth rows are given; the rest is one multiplication and one subtraction. The row worth sitting with is the third, because three hundred bad calls a day exist before any check is written, and the sixth row is that number put on a clock.

Refusing in a way the model can use

A rejection is not the end of the interaction. It goes back into the conversation, the model reads it, and it tries again. So the rejection is an instruction, and its quality determines whether the second attempt is right.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Saying Something and Doing Something
  2. 02The Loopopening only
  3. 03Describing a Tool Wellopening only
  4. 04Checking What the Model Asked Foryou are here
  5. 05When a Tool Failsopening only
  6. 06Several Steps and a Budgetopening only
  7. 07Text From Outside Is Not an Instructionopening only
  8. 08Judging Whether the Whole Thing Workedopening only

Read alongside