npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nqbao/pi-json-schema

v0.1.1

Published

Pi extension for validating and writing structured JSON output against a JSON Schema.

Downloads

403

Readme

@nqbao/pi-json-schema

@nqbao/pi-json-schema is a Pi extension that enforces structured JSON output against a caller-provided JSON Schema.

It registers a json_output tool, validates the final payload with ajv, and writes the validated JSON to a file. If the tool is not called, it can optionally attempt one fallback extraction pass from the last assistant message.

Install

Install the extension through Pi:

pi install npm:@nqbao/pi-json-schema

Usage

After installation, the extension is available automatically:

pi -p "Extract company name and revenue from: Acme Corp reported 5 million dollars in revenue last quarter" \
  --json-schema '{"type":"object","properties":{"company":{"type":"string"},"revenue":{"type":"number"}},"required":["company","revenue"]}' \
  --json-output /tmp/result.json

Expected output file:

{
  "company": "Acme Corp",
  "revenue": 5000000
}

Flags

  • --json-schema: JSON Schema string that the final output must satisfy.
  • --json-output: file path where validated JSON will be written.
  • --json-fallback: fallback behavior when json_output was not called.

Fallback modes:

  • best-effort: try one follow-up extraction pass with the configured model. This is the default.
  • force: same as best-effort, but forces the follow-up model call to choose json_output.
  • none: do not attempt fallback; fail if the final assistant message does not contain valid JSON.

Behavior

  • If --json-output is not set, the extension stays inactive.
  • If --json-output is set, --json-schema is required.
  • The agent is expected to call json_output as its last action.
  • If the tool was not called, the extension first checks whether the last assistant message already contains valid JSON.
  • If there is no assistant message at all, the extension does nothing during shutdown and leaves the upstream run failure unchanged.

Local Development

When working in this repo directly, load the extension from the local file instead of the installed package name:

pi -p "Extract company name and revenue from: Acme Corp reported 5 million dollars in revenue last quarter" \
  --extension ./index.ts \
  --json-schema '{"type":"object","properties":{"company":{"type":"string"},"revenue":{"type":"number"}},"required":["company","revenue"]}' \
  --json-output /tmp/result.json

Install dependencies:

npm install

Run the existing end-to-end test harness:

bash test/run.sh

Test prerequisites:

  • pi must be installed and available on PATH.
  • model/API credentials must already be configured for Pi.
  • jq must be installed.