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

positional-zod

v0.1.1

Published

Schema-driven positional format for LLM structured outputs

Readme

positional-zod

Schema-driven positional format for LLM structured outputs. Save ~56% on completion tokens compared to JSON.

Why?

LLMs output JSON with lots of redundant tokens (quotes, brackets, keys). positional-zod uses a compact positional format:

// JSON output (262 tokens)
[{"sku":"WATCH-001","name":"Apple Watch","brand":"Apple","price":799,"rating":4.9},...]

// Positional output (114 tokens) - 56% smaller!
WATCH-001|Apple Watch|Apple|799|4.9

Installation

npm install positional-zod zod
# Plus your preferred LLM SDK
npm install openai        # for OpenAI
npm install @anthropic-ai/sdk  # for Anthropic
npm install @google/generative-ai  # for Google

Quick Start

import { PositionalZod } from "positional-zod";
import { z } from "zod";

// 1. Create instance
const pz = new PositionalZod({
  providers: {
    openai: { apiKey: process.env.OPENAI_API_KEY },
  },
  defaultProvider: "openai",
});

// 2. Define schema
const UserSchema = z.object({
  id: z.number(),
  name: z.string(),
  score: z.number(),
});

// 3. Extract data
const result = await pz.complete({
  prompt: "Extract the top 3 users from this leaderboard",
  inputData: leaderboardText,
  schema: UserSchema,
  mode: "array",
});

console.log(result.data);
// [
//   { id: 1, name: "Alice", score: 95.5 },
//   { id: 2, name: "Bob", score: 87.0 },
//   { id: 3, name: "Charlie", score: 92.3 }
// ]

Token Savings

Real-world benchmark extracting 5 products from a catalog:

| Method | Prompt Tokens | Completion Tokens | Total | Savings | |--------|---------------|-------------------|-------|---------| | JSON → JSON | 1053 | 262 | 1315 | baseline | | JSON → PositionalZod | 1185 | 114 | 1299 | -56% completion | | TOON → PositionalZod | 939 | 117 | 1056 | -20% total |

Features

  • Multi-provider: OpenAI, Anthropic, Google Gemini
  • Zod v3 & v4: Full compatibility
  • Type-safe: Full TypeScript support
  • Nested objects: Automatically flattened
  • Arrays: Inline with sub-delimiters
  • Optional fields: Handled gracefully
  • Validation: Zod validation on parsed output

API

PositionalZod(config)

const pz = new PositionalZod({
  providers: {
    openai: { apiKey: "...", model: "gpt-4o-mini" },
    anthropic: { apiKey: "...", model: "claude-sonnet-4-20250514" },
    google: { apiKey: "...", model: "gemini-2.0-flash" },
  },
  defaultProvider: "openai",
  fallbackProviders: ["anthropic", "google"], // optional
  delimiter: "|",      // default
  subDelimiter: ";",   // for arrays
  debug: false,
});

pz.complete(options)

const result = await pz.complete({
  prompt: "Extract users",
  schema: UserSchema,
  mode: "array",           // "object" | "array"
  inputData: data,         // optional
  inputFormat: "json",     // "json" | "text" | "auto"
  provider: "openai",      // override default
  temperature: 0,
  maxTokens: 1000,
  maxRows: 10,             // limit array results
  systemPrompt: "...",     // additional instructions
});

// Result
{
  data: [...],             // parsed & validated
  rawResponse: "...",      // raw LLM output
  provider: "openai",
  rowCount: 3,             // for array mode
  usage: {
    promptTokens: 100,
    completionTokens: 50,
    totalTokens: 150,
  },
  warnings: [],            // any parse warnings
}

Supported Schema Types

z.string()
z.number()
z.boolean()
z.date()
z.enum(["a", "b", "c"])
z.literal("value")
z.array(z.string())        // uses sub-delimiter
z.array(z.object({...}))   // inline JSON
z.object({...})            // flattened with dots
z.optional()
z.nullable()

Combine with TOON for Maximum Savings

Use TOON for input encoding + PositionalZod for output:

import { encode } from "@toon-format/toon";

const result = await pz.complete({
  prompt: "Extract products",
  inputData: encode(catalogData),  // TOON-encoded input
  schema: ProductSchema,
  mode: "array",
});

This gives you ~20% total token savings (input + output combined).

License

MIT