Anleitungen

How to Get JSON Output From an LLM

Design a strict JSON contract, handle missing values, and validate model output before your application uses it.

Dieser Prompt ist derzeit auf Englisch verfügbar. Die Oberfläche bleibt in der gewählten Sprache.

Define a schema List every key, type, allowed value, and whether it is required. Specify how missing or uncertain information must be represented.

Remove competing prose Ask for one JSON value with no markdown fence or commentary. When supported, prefer the provider’s structured-output or schema feature over prompt-only formatting.

Validate outside the model Parse the response, validate it against a schema, reject unexpected fields when appropriate, and retry with the validation error. Never treat generated JSON as trusted code or SQL.

Test edge cases Include empty inputs, quotes, Unicode, long strings, ambiguous categories, and unavailable facts. Correct escaping and stable null behavior matter as much as the happy path.