.agent/skills/llm-output-parsing/SKILL.md
Parse and validate structured output from LLMs — JSON mode, Zod validation, retry on bad output. Use when any agent needs reliable structured data from an LLM response.
npx skillsauth add abzhaw/juliaz_agents llm-output-parsingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'Always respond with valid JSON.' },
{ role: 'user', content: prompt }
],
response_format: { type: 'json_object' }
});
const data = JSON.parse(response.choices[0].message.content!);
import { z } from 'zod';
const TaskSchema = z.object({
title: z.string(),
priority: z.enum(['low', 'medium', 'high']),
due_date: z.string().optional(),
});
async function parseWithRetry<T>(
prompt: string,
schema: z.ZodSchema<T>,
maxRetries = 3
): Promise<T> {
for (let i = 0; i < maxRetries; i++) {
const raw = await callLLM(prompt + '\nRespond with valid JSON only.');
try {
const json = JSON.parse(raw);
return schema.parse(json);
} catch (err) {
if (i === maxRetries - 1) throw new Error(`Failed to parse after ${maxRetries} attempts`);
prompt += `\n\nPrevious attempt failed: ${err.message}. Try again.`;
}
}
}
// Extract JSON from mixed-content responses
function extractJSON(text: string): object | null {
const match = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/(\{[\s\S]*\})/);
if (!match) return null;
try { return JSON.parse(match[1]); } catch { return null; }
}
const response = await openai.beta.chat.completions.parse({
model: 'gpt-4o-2024-08-06',
messages,
response_format: zodResponseFormat(TaskSchema, 'task')
});
const task = response.choices[0].message.parsed; // fully typed
development
Fortschrittsverfolgung der Masterarbeit. Wortanzahl pro Kapitel, Fertigstellungsgrad, fehlende Elemente, Deadlines. Haelt den Ueberblick.
development
Kapitelarchitektur und Gliederung der Masterarbeit. Verwaltet die Struktur, schlaegt vor wo Inhalte hingehoeren, validiert den logischen Fluss zwischen Kapiteln.
tools
Konvertiert Protokolleinträge und Session-Logs in thesis-fähiges deutsches Narrativ. Transformiert Entwicklungsdokumentation in akademische Prosa.
research
Sucht und analysiert akademische Literatur. Findet relevante Papers, erstellt strukturierte Zusammenfassungen. Zitiert NIEMALS — schlaegt nur vor.