Agent skill

JSON Mode Patterns

by softspark in softspark/ai-toolkit

Structured JSON output from Claude: native JSON schemas, strict tools, local validation, refusal and truncation handling.

Apache-2.0Auto-check passedAI & LLM Engineering

Install JSON Mode Patterns

skills CLI
$ npx skills add softspark/ai-toolkit --skill json-mode-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install softspark/ai-toolkit json-mode-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/softspark/ai-toolkit.git skills-src && mkdir -p .claude/skills && cp -r skills-src/app/skills/json-mode-patterns .claude/skills/json-mode-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
json-mode-patterns
GitHub stars
179
Token cost
~1.2k tokens
SKILL.md length
343 words
Files
1
Skills in repo
112
Repo updated
First seen
Licence
Apache-2.0

At a glance

Structured JSON output from Claude: native JSON schemas, strict tools, local validation, refusal and truncation handling.

  • Tasks that involve Structured output and tool calling
  • SKILL.md covers Native JSON response, Strict tool arguments, Failure handling and Schema and SDK details, plus 1 more section
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

JSON Mode Patterns is an agent skill from softspark/ai-toolkit. Structured JSON output from Claude: native JSON schemas, strict tools, local validation, refusal and truncation handling. Triggers: JSON mode, structured output, schema validation, JSON parsing.

Its SKILL.md is about 1.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in AI & LLM Engineering, covering Structured output and tool calling. The repository describes itself as: Professional-grade AI coding toolkit: 94 skills, 44 agents, multi-platform (Claude, Cursor, Windsurf, Copilot, Gemini, Cline, Roo Code, Aider, Augment, Antigravity, Codex CLI… The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Structured output and tool calling

Example prompts

  • “/json-mode-patterns”

Requirements

  • Python 3
  • Pre-approved tools (allowed-tools): Read

What it can do on your machine

Read from SKILL.md and the folder at commit d64db2b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are python).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • platform.claude.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

JSON Mode Patterns loads about 1.2k tokens when it runs. Until then it costs about 53 tokens; SKILL.md has 343 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~53
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from softspark/ai-toolkit at commit d64db2b, republished under its Apache-2.0 licence (© softspark). 343 words, ~1,217 tokens.

Download SKILL.mdSave it as .claude/skills/json-mode-patterns/SKILL.md (or your agent's skills folder).
name
json-mode-patterns
description
Structured JSON output from Claude: native JSON schemas, strict tools, local validation, refusal and truncation handling. Triggers: JSON mode, structured output, schema validation, JSON parsing.
allowed-tools
Read
effort
medium
user-invocable
false

JSON Mode Patterns

Use native JSON outputs through output_config.format for a structured response. Use strict: true on a tool when its arguments need constrained decoding. Forcing a tool call alone does not guarantee schema compliance.

Native JSON response

This example uses the current Messages API shape. The caller supplies the approved model and output budget. Numeric limits are checked locally because raw structured output schemas do not support minimum and maximum.

python
import json
import math

ANALYSIS_SCHEMA = {
    "type": "object",
    "properties": {
        "sentiment": {"type": "string", "enum": ["positive", "neutral", "negative"]},
        "confidence": {"type": "number"},
        "themes": {"type": "array", "items": {"type": "string"}},
    },
    "required": ["sentiment", "confidence", "themes"],
    "additionalProperties": False,
}


def validate_analysis(result):
    if not isinstance(result, dict) or set(result) != set(ANALYSIS_SCHEMA["required"]):
        raise ValueError("Unexpected analysis fields")
    sentiment = result["sentiment"]
    if not isinstance(sentiment, str) or sentiment.casefold() not in {"positive", "neutral", "negative"}:
        raise ValueError("Unknown sentiment")
    confidence = result["confidence"]
    if (type(confidence) not in (int, float)
            or not 0 <= confidence <= 1 or not math.isfinite(confidence)):
        raise ValueError("Confidence must be finite and between zero and one")
    themes = result["themes"]
    if not isinstance(themes, list) or not 1 <= len(themes) <= 10 or not all(isinstance(t, str) for t in themes):
        raise ValueError("Expected one to ten theme strings")
    return {**result, "sentiment": sentiment.casefold()}


def analyze(client, model, text, max_tokens):
    response = client.messages.create(
        model=model,
        max_tokens=max_tokens,
        messages=[{"role": "user", "content": text}],
        output_config={"format": {"type": "json_schema", "schema": ANALYSIS_SCHEMA}},
    )
    if response.stop_reason != "end_turn":
        raise ValueError(f"Analysis incomplete: {response.stop_reason}")
    blocks = [block.text for block in response.content if block.type == "text"]
    if len(blocks) != 1:
        raise ValueError("Expected one structured response")
    return validate_analysis(json.loads(blocks[0]))

Treat the returned confidence as an uncalibrated score until evaluated on labeled data. Schema compliance does not establish factual correctness.

Strict tool arguments

For a real tool, put "strict": True beside name and input_schema. Require additionalProperties: False on each object and validate business rules before executing any side effect. Check the expected tool name, content block type and stop_reason == "tool_use".

Forced tool_choice has thinking-mode restrictions. Verify the selected model's tool-choice contract before combining it with adaptive or extended thinking; do not silently disable thinking or change models to force a function call.

Failure handling

  • Check refusal and max_tokens before parsing. Neither is a successful structured result.
  • Retry only within the caller's approved attempt and token limits. Never increase a spending limit automatically.
  • Do not close truncated braces or extract the first regex-matched object and treat it as valid.
  • If a proxy lacks native structured outputs, parse the entire response and validate it locally; failure is an explicit error or review item.
  • For streaming, wait for completion and the final stop reason before validating assembled text.

Schema and SDK details

Raw schemas support a subset of JSON Schema. Numeric ranges, string length bounds, recursive schemas and most array-length constraints are unsupported. Apply these locally or use client.messages.parse(output_format=YourPydanticModel), whose SDK helper translates the schema and validates the original model afterward.

The SDK helper's output_format argument is not the raw Messages API field: messages.create uses output_config.format. No structured-output beta header is required. Check enum casing locally; avoid labels differing only by case.

Reviewed 2026-09-23:

Use content-moderation-patterns for decision routing and model-routing-patterns for choosing among approved models.

© softspark, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in app/skills/json-mode-patterns of softspark/ai-toolkit.

Open the folder on GitHubat commit d64db2b

Compare with similar skills

JSON Mode Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

JSON Mode Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
JSON Mode Patterns this skillsoftspark/ai-toolkit179—~1.2kAutomated safety check: PassApache-2.0
Planning With Filesjarrodwatts/claude-code-config1.1k5 repos~967Automated safety check: PassNone
Tool Use Data Synthesissunny-glow/Auto-BenchMax1.3k—~3.3kAutomated safety check: PassNone
Agent Harness ConstructionKartikLabhshetwar/mind-mentor1477 repos~500Automated safety check: PassApache-2.0
Prompt Engineering Patternswshobson/agents40k—~1.3kAutomated safety check: PassMIT
Model Benchmarkstheopenco/llmgateway1.7k—~1.1kAutomated safety check: NotesCustom licence

Similar skills

  • Planning With Files

    jarrodwatts/claude-code-config

    Transforms workflow to use Manus-style persistent markdown files for planning, progress tracking, and knowledge storage.

    1.1k GitHub starsUsed in 5 repos~967 tokens
    AI & LLM EngineeringAuto-check passed
  • Tool Use Data Synthesis

    sunny-glow/Auto-BenchMax

    Synthesize training data for ANY tool-use / agentic benchmark, in ANY repo.

    1.3k GitHub stars~3.3k tokensUpdated 2 mo ago
    AI & LLM EngineeringAuto-check passed
  • Agent Harness Construction

    KartikLabhshetwar/mind-mentor

    Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates.

    147 GitHub starsUsed in 7 repos~500 tokens
    AI & LLM EngineeringAuto-check passed
  • Reference for designing and tuning production LLM prompts: few-shot examples, chain-of-thought, structured outputs, templates and system prompts.

    40k GitHub stars~1.3k tokensUpdated 2 days ago
    AI & LLM EngineeringAuto-check passed
  • Model Benchmarks

    theopenco/llmgateway

    Run and report repository model or provider-mapping benchmarks.

    1.7k GitHub stars~1.1k tokensUpdated today
    AI & LLM EngineeringAuto-check: notes
  • Agent Prompt Quality Bar

    mastra-ai/mastra

    Universal quality bar and final audit rubric for any agent system prompt.

    29k GitHub stars~2k tokensUpdated today
    AI & LLM EngineeringAuto-check passed

More from softspark/ai-toolkit

All 112 skills in this repo
  • Prepare Test Env

    softspark/ai-toolkit

    Prepare or verify a project QA environment with source identity, readiness, browser access, evidence paths and owned cleanup.

    179 GitHub stars~1.8k tokensUpdated today
    Auto-check: notes
  • A11y Validate

    softspark/ai-toolkit

    Accessibility validator: WCAG 2.1 AA, EN 301 549, EAA. An agent skill from softspark/ai-toolkit.

    179 GitHub stars~3.8k tokensUpdated today
    Auto-check: notes
  • Analyze

    softspark/ai-toolkit

    Analyzes code quality, complexity, patterns across codebase.

    179 GitHub stars~1k tokensUpdated today
    Auto-check passed
  • Autonomous Dev

    softspark/ai-toolkit

    Drives a brief, specification, issue or existing PR through implementation, review, tests and QA to a ready PR.

    179 GitHub stars~2.6k tokensUpdated today
    Auto-check: notes
  • Brand Voice

    softspark/ai-toolkit

    Direct technical voice for docs, README, user-facing text. An agent skill from softspark/ai-toolkit.

    179 GitHub stars~2.1k tokensUpdated today
    Auto-check passed
  • CI

    softspark/ai-toolkit

    Detect/generate/debug CI pipeline config (GitHub Actions, GitLab CI).

    179 GitHub stars~1.1k tokensUpdated today
    Auto-check: notes

Questions about JSON Mode Patterns

What does JSON Mode Patterns do?

Structured JSON output from Claude: native JSON schemas, strict tools, local validation, refusal and truncation handling. JSON Mode Patterns is an agent skill from softspark/ai-toolkit. Structured JSON output from Claude: native JSON schemas, strict tools, local validation, refusal and truncation handling.

When should I use JSON Mode Patterns?

JSON Mode Patterns fits situations like: tasks that involve Structured output and tool calling.

How do I install JSON Mode Patterns in Claude Code?

Run `npx skills add softspark/ai-toolkit --skill json-mode-patterns -a claude-code`. Or copy the skill folder (app/skills/json-mode-patterns in softspark/ai-toolkit) into .claude/skills/json-mode-patterns in your project. Claude Code loads it when a task matches its description.

How do I install JSON Mode Patterns in Codex?

Run `npx skills add softspark/ai-toolkit --skill json-mode-patterns -a codex`. Or copy the skill folder (app/skills/json-mode-patterns in softspark/ai-toolkit) into .agents/skills/json-mode-patterns in your project. Codex loads it when a task matches its description.

Can I use JSON Mode Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add softspark/ai-toolkit --skill json-mode-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/json-mode-patterns, .gemini/skills/json-mode-patterns, .github/skills/json-mode-patterns and .opencode/skills/json-mode-patterns in your project.

What does JSON Mode Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: JSON Mode Patterns is instructions for the agent only. Our summary lists: Python 3. Its frontmatter pre-approves these tools: Read.

Does JSON Mode Patterns access the network?

SKILL.md names 1 domain. As links in the text: platform.claude.com. This is read from the text; nothing was executed.

Is JSON Mode Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does JSON Mode Patterns use?

JSON Mode Patterns is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does JSON Mode Patterns use?

About 1.2k tokens (SKILL.md is roughly 4.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to JSON Mode Patterns?

Skills that share tags, products or a category with JSON Mode Patterns: Planning With Files (jarrodwatts/claude-code-config, 1.1k stars), Tool Use Data Synthesis (sunny-glow/Auto-BenchMax, 1.3k stars), Agent Harness Construction (KartikLabhshetwar/mind-mentor, 147 stars) and Prompt Engineering Patterns (wshobson/agents, 40k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains JSON Mode Patterns?

softspark (a GitHub user) maintains it in softspark/ai-toolkit, which has 179 GitHub stars. The repository holds 112 skills in this directory. The repository was last updated on October 7, 2026.

Source: softspark/ai-toolkit on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.