Skip to content

[rig-sampler] feat(s): add s.null schema helper for the JSON null literal type#26

Merged
pelikhan merged 1 commit into
mainfrom
rig-sampler/07-summarize-many-files-0982d2da3938bc95
Jul 23, 2026
Merged

[rig-sampler] feat(s): add s.null schema helper for the JSON null literal type#26
pelikhan merged 1 commit into
mainfrom
rig-sampler/07-summarize-many-files-0982d2da3938bc95

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Sample run

Sample: src/samples/07-summarize-many-files.ts

The agent uses s.object({ files: s.string }) as input (with a p.bash(...) prompt intent) and s.object({ summary: s.string }) as output. The run completed in 1 turn with no repair loops — clean success.

What the run revealed

While the sample itself ran smoothly, reading the code during analysis exposed a gap in the s.* schema helper API: there is no s.null helper for the JSON null literal type.

null is a valid JSON value (it appears in the Json type union), yet authors had no way to declare a null-typed output field or a nullable slot in a schema. The only workaround was to use s.unknown, which is too loose and disables validation entirely.

Change

  • New type: NullSchema = { type: "null"; description?: string }
  • Schema union: NullSchema added alongside the other primitives
  • InferSchema: T extends { type: "null" } ? null branch added for correct TypeScript inference
  • validateSchema: schema.type === "null" check — accepts only null, rejects everything else with a clear error message
  • s.null: helper added to the exported s object, callable as s.null or s.null("description"), consistent with all other primitive helpers
  • createTypedPrimitiveSchema constraint: extended to include NullSchema
  • Tests: 5 new tests covering serialization, validation acceptance/rejection, TypeScript inference, and use as an object field

Why this improves the harness

Without s.null, schema authors writing agents that reset a field, clear a value, or emit an explicit "no result" were forced to use s.unknown (disabling validation) or s.optional (which models absence, not null). s.null is a direct, self-documenting solution that slots neatly into the existing s.* API surface with no breaking changes.

Generated by Daily Rig Sampler · 91.9 AIC · ⌖ 8.63 AIC · ⊞ 5.2K ·

Add NullSchema type, s.null helper, InferSchema<NullSchema> → null,
validateSchema null check, and test coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review July 23, 2026 09:44
@pelikhan
pelikhan merged commit 23d3254 into main Jul 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant