Prompt

LLM API with JSON output

Artificial Intelligence / AI Platforms1 observationLast seen Oct 8, 2026

Latest observation

Oct 8, 2026OpenAI APIWeb search: off

If you want an LLM API to return JSON-only output, there are a few common approaches depending on the provider.

General options

1. Prompt for JSON

Ask the model explicitly:

  • “Return valid JSON only.”
  • “Do not include markdown, explanations, or code fences.”

Example prompt:

Extract the following fields and return valid JSON only:
- name
- email
- phone

2. Use structured output / JSON mode

Some APIs support a built-in JSON response mode or schema enforcement.

Examples:

  • OpenAI: structured outputs / JSON schema
  • Anthropic: tool use / structured formatting
  • Google Gemini: JSON output mode
  • Azure OpenAI: similar capabilities depending on model/deployment

3. Use function calling / tool calling

Instead of free-form text, define a function schema and have the model fill it. This is often the most reliable way to get structured data.

Example schema:

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "email": { "type": "string" }
  },
  "required": ["name", "email"],
  "additionalProperties": false
}

Practical recommendation

If your API supports it, use:

  1. JSON schema / structured outputs for strict validation
  2. Function calling if you need the output to map directly into an application
  3. A fallback prompt-only JSON instruction if the model doesn’t support structured mode

Important

Even with JSON mode, you should still:

  • validate the response
  • handle malformed or incomplete JSON
  • retry if needed

If you want, I can give you:

  • an OpenAI API example
  • a Python example
  • a Node.js example
  • or a provider comparison for JSON output

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.