Menu

Your Schema Said Every Field Was Required So the Model Invented a Date
📰

Your Schema Said Every Field Was Required So the Model Invented a Date

DEV Community: backend·Serguey Asael Shinder·10 days ago
#UHQOjWsE
#devtobackend#devto#dev#date#model
Reading 0:00
15s threshold

The supplier emails were a mess.

Free text,

forwarded chains,

the odd photo of a printed page.

So you gave them to a model

with a schema.

Order number.

Quantity.

Delivery date.

Strict structured output,

so the reply

always parsed.

It always parsed.

For six weeks

the warehouse booked slots

straight from the extracted dates.

Then a lorry turned up

on a day nobody expected,

and another failed to turn up

on a day somebody did.

The email behind the second one

said, in full,

we will confirm the date next week.

The model had returned

a delivery date anyway.

The fourteenth of March.

Plausible.

Well formatted.

Nowhere in the email.

Here is the mechanism.

Strict mode

does not ask the model nicely.

It constrains the decoding.

At every step,

only tokens that keep the output

valid against your schema

are allowed out.

In the strict mode

most teams use,

every field has to be listed

as required.

Optional is spelled differently.

A field that may be empty

has to accept null

as one…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.