Urgent.News

What's breaking now, across thousands of outlets.

AI

I Put `minimum` in My JSON Schema. ShapeCraft Ignored It. That Was By Design

I was extracting customer details from onboarding messages. The result needed a name, an age, and a country code before it could be passed to the account service. The schema looked strict enough: const PersonJsonSchema = { type : " object " , required : [ " name " , " age " , " country " ], properties : { name : { type : " string " , minLength : 3 }, age : { type : " number " , minimum : 18 ,…

The author extracted customer details from onboarding messages, requiring a name, age, and country code. They created a JSON Schema with required fields and specific constraints, including minimum age, maximum age, and uppercase country codes. However, when a test message contained a 12-year-old, the response was still valid JSON and passed through the account service.

The author initially tried to fix the issue by adding more instructions to the prompt, but this did not guarantee adherence to the constraints. They used ShapeCraft to parse and validate the response, assuming the minimum and pattern keywords were enforced there. When the minimum and pattern keywords were not enforced, the author initially treated it as a bug, but later realized it was a deliberate design choice.

The built-in JSON Schema checker only checks types, enum membership, required fields, nested properties, and array items. It does not implement every possible JSON Schema keyword, which was a better design boundary than silently having each backend behave differently. The author then used AJV to create a strict validator for the required keywords. They compiled the schema once and passed a function to generate() to validate the parsed value.

The custom validator only affects validation for inputs with the { jsonSchema } format. Zod schemas remain unaffected. The custom validator only changes validation for inputs with the { jsonSchema } format, while Zod schemas continue to work as intended.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

How to Build AI Monitoring Agents: 4 Rules for Catching Time-Sensitive Events

Run a WHOIS lookup on any domain name and you get back a status code. Not a paragraph, not a guess. A code, from a standardized list of seventeen, published by ICANN, that tells you exactly where that…

  • Define specific criteria for agent activation before building.
  • Use declared state when possible, acknowledging model limitations.
  • Monitor faster than the opportunity window to avoid missing events.

The Part of AI Coding Agents I Didn't Expect to Care About: Latency

I spent the last few months pretty much living in Claude Code. It became a regular part of how I worked: give it a task, let it work through the codebase, review what it changed, and keep iterating.

  • Latency significantly impacts productivity, causing distractions and context switches
  • Rapid feedback loop with low latency maintains developer focus and momentum
  • Latency is a crucial metric beyond code quality and reasoning abilities

More from Monday 7 September →