json-mode-patterns

json-mode-patterns is a skill for Claude Code from softspark/ai-toolkit. It costs 39 tokens per session (1,047 once invoked), scanned A, original, Apache-2.0.

A guide to returning structured JSON from Claude, an AI model, by defining a tool whose input schema describes the required data. It also covers parsing results and recovering from incomplete output.

In plain words
What is it for?
Use it to design JSON schemas, force a model to return a specific structure, parse tool results, and handle partial responses.
Why use it?
It helps applications receive predictable machine-readable data when the model does not provide a dedicated JSON-response setting. This reduces errors when validating or processing model responses.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the ai-toolkit plugin — 113 skills, 44 agents, 14 hooks shipped together

Good fit Use it to design JSON schemas, force a model to return a specific structure, parse tool results, and handle partial responses.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/softspark/ai-toolkit/json-mode-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add softspark/ai-toolkit --skill json-mode-patterns
Clone the repo
git clone --depth 1 https://github.com/softspark/ai-toolkit

Made for: Claude Code.

Or install ai-toolkit, the plugin that ships this one along with the rest of its 113 skills, 44 agents, 14 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for json-mode-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/softspark/ai-toolkit/json-mode-patterns.svg)](https://agentmods.dev/skills/softspark/ai-toolkit/json-mode-patterns)
Your own site
<a href="https://agentmods.dev/skills/softspark/ai-toolkit/json-mode-patterns"><img src="https://agentmods.dev/badge/skills/softspark/ai-toolkit/json-mode-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 39 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,047 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00039 $0.01047
Opus 5 $0.00019 $0.00524
Sonnet 5 $0.00008 $0.00209
Haiku 4.5 $0.00004 $0.00105

Measured 4d ago against content hash c2551f80f367, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

json-mode-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

app/skills/json-mode-patterns/SKILL.md · 125 lines

How it starts

The opening of the file, as written. The whole thing — 125 lines — stays where its author put it; the contents beside it link to each section on GitHub.

JSON Mode Patterns

Claude does not have a dedicated response_format: json parameter like some other APIs. The idiomatic way to get guaranteed JSON is tool use with a forced function call. This skill documents that pattern plus fallbacks.

Preferred Pattern: Tool-as-Schema

Define a tool whose input schema IS the JSON shape you want, then force the model to call it.

tools = [{
    "name": "record_analysis",
    "description": "Return the analysis as structured data",
    "input_schema": {
        "type": "object",
        "properties": {
            "sentiment": {"type": "string", "enum": ["positive", "neutral", "negative"]},
            "confidence": {"type": "number", "minimum": 0, "maximum": 1},
            "themes": {"type": "array", "items": {"type": "string"}}
        },
        "required": ["sentiment", "confidence", "themes"]
    }
}]

response = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    tools=tools,
    tool_choice={"type": "tool", "name": "record_analysis"},
    messages=[{"role": "user", "content": text_to_analyze}]
)

# The structured result is in response.content
for block in response.content:
    if block.type == "tool_use" and block.name == "record_analysis":
        result = block.input  # already a Python dict, schema-validated
        break

Why this wins:

  • Schema is enforced at the API level
  • No regex or parsing from model text
  • Enums, min/max, required fields actually constrain the output

Fallback: Prompted JSON + Strict Parse

When tool use is unavailable (some SDKs/proxies strip it):

response = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    system="You return ONLY valid JSON. No prose, no markdown fences.",
    messages=[{
        "role": "user",
        "content": f"Extract as JSON matching this schema: {schema_str}\n\nInput: {text}"
    }]
)

import json
try:
    result = json.loads(response.content[0].text)
except json.JSONDecodeError:
    # Claude sometimes wraps in ```json ... ```
    result = json.loads(strip_markdown_fence(response.content[0].text))

Read the full file on GitHub · 125 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 125 lines · 39 tokens per session scan A c2551f80f367

Subscribe to this mod's changes

json-mode-patterns is a skill published in the GitHub repository softspark/ai-toolkit (170 stars, last pushed today), licensed Apache-2.0. It adds 39 tokens to every session and 1,047 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

roo-fix-volatile-msg

Ladder-aware Roo Code Anthropic caching — verify the rolling read/write ladder on the wire, then close the real gaps (Vertex 4-block budget, MiniMax path).

OnlyTerp/prompt-cache-skills · 42 tokens

ai-agent-builder

Conception et implémentation d'agents IA autonomes avec outils, mémoire et orchestration. Se déclenche avec "agent IA", "AI agent", "autonomous agent", "tool use", "function calling", "agent framework", "LangChain agent", "CrewAI", "AutoGen", "agent loop", "ReAct". Also triggers on "build an AI agent", "agent with…

khalilbenaz/claude-skills-collection · 90 tokens

ai-workflow-orchestrator

Orchestration de workflows IA complexes avec chaînes et pipelines. Se déclenche avec "workflow IA", "LangChain", "LangGraph", "pipeline IA", "chaîne de prompts", "orchestration LLM", "AI pipeline", "multi-step AI". Also triggers on "chain LLM calls", "orchestrate AI steps".

khalilbenaz/claude-skills-collection · 77 tokens

model-strategy

Multi-model orchestration and model-switching strategy. Score-based model selection, reasoning-effort routing, cross-agent delegation (Gemini, Codex, Ollama), advisor pairing, escalation triggers, permission matrix, and cost-efficiency optimization.

ellmos-ai/skills · 52 tokens

creator-prompt-engineer

Convert creative-department outputs (script, vision, cinematography, characters, sets, storyboards, shots) into producible, consistent AI image/video prompts — with tool-specific optimization, locked anchors, negative prompts, and safe alternatives. Default image tool priority for storyboard/character sheets is GPT…

ilkaydemiralay/vision_art_creator · 135 tokens

continue-gemini-explicit

Continue's Gemini provider doesn't use the cachedContents API at all. Add explicit caching for sessions over the minimum token threshold.

OnlyTerp/prompt-cache-skills · 31 tokens