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 ran1101
is the caller permitted1102
is it the right shape of1101
is the action rate limit1102
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
calls made
the share of them that are bad in some way
bad calls you are willing to let through
the share of bad calls validation must catch
Five thousand calls a day, six per cent of them bad in some way, and a tolerance of thirty reaching the tools means validation has to catch about ninety per cent of them. That is achievable with the four mechanical checks and it is worth noticing what the arithmetic also says: at this rate three hundred bad calls a day are being produced, so a system with no validation at all is not occasionally wrong, it is wrong three hundred times before lunch.

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