@qzsy/zod-to-arrow
v0.2.2
Published
JSON Schema to arrow prewarm prompt
Keywords
Readme
@qzsy/zod-to-arrow
Generate arrow format prewarm prompts from JSON Schema (typically produced by zod-to-json-schema). Teaches the LLM how to write scalar fields, nested objects, string arrays, and object arrays (ITEM -> START ... END).
Install
npm install @qzsy/zod-to-arrow @qzsy/arrow-parserQuick start
import { schemaToArrowPrompt } from "@qzsy/zod-to-arrow";
const schema = {
type: "object",
properties: {
title: { type: "string" },
strengths: { type: "array", items: { type: "string" } },
dimensions: {
type: "array",
items: {
type: "object",
properties: {
description: { type: "string" },
chartType: { type: "string" },
},
},
},
},
required: ["title", "strengths"],
};
const systemPrompt = schemaToArrowPrompt(schema, "课堂评价结果");Generated prompt includes:
- Rules for
DATA -> START/DATA -> END - String array:
STRENGTHS -> START+ plain lines +STRENGTHS -> END - Object array:
DIMENSIONS -> START+DIMENSION -> START ... DIMENSION -> END - Example structure and explicit bad cases (no JSON arrays)
API
| Export | Description |
|--------|-------------|
| schemaToArrowPrompt(schema, purpose) | Full system prompt for LLM arrow output |
| schemaToArrowSchemaBlock(schema) | Documentation / secondary-agent SCHEMA block |
| JsonSchema | Re-exported type from @qzsy/arrow-parser |
Full pipeline
import { schemaToArrowPrompt } from "@qzsy/zod-to-arrow";
import { parseToJson } from "@qzsy/arrow-parser";
import { z } from "zod";
const EvalResult = z.object({
strengths: z.array(z.string()),
suggestions: z.array(z.string()),
});
const schema = zodToJsonSchema(EvalResult);
const prompt = schemaToArrowPrompt(schema, "评价结果");
// 1. Send prompt + context to LLM → arrow text
// 2. Parse:
const data = parseToJson(llmOutput, schema);
// 3. Validate:
const result = EvalResult.safeParse(data);Version
0.2.0 — aligned with Go SchemaToArrowPrompt; array/object examples; bad-case hints.
See also: @qzsy/arrow-parser · 箭头格式规范.md
