Copilot Prompts That Output Strict JSON Schemas for API Use
🔍 WiseChecker

Copilot Prompts That Output Strict JSON Schemas for API Use

When you need Copilot to generate data that another program or API can consume directly, free-form text output causes errors. You need strict JSON schemas — structured output with exact field names, data types, and validation rules. This article explains how to write Copilot prompts that produce valid, schema-compliant JSON every time. You will learn the exact prompt structure, schema definition techniques, and common formatting pitfalls to avoid.

Key Takeaways: Strict JSON Schema Prompts for Copilot

  • Prompt structure: “Output a JSON object with the following schema:” Forces Copilot to return a JSON object instead of plain text or Markdown.
  • Schema definition with JSON Schema syntax: Use "type": "object", "properties", and "required" fields to define exact field names and data types.
  • Validation rule: "additionalProperties": false Prevents Copilot from adding extra fields that break your API contract.

ADVERTISEMENT

How to Structure a Prompt for Strict JSON Output

Copilot, by default, returns responses in natural language or Markdown. To get strict JSON, you must explicitly instruct the model to output a JSON object and define the schema inside the prompt. The key components are: a clear instruction to output JSON, a schema definition using JSON Schema syntax, and a request to omit any explanatory text. Without these three elements, Copilot may wrap the JSON in a code block or add descriptive sentences around it.

The schema definition acts as a template. Copilot fills in the values based on your request, but it respects the structure you define. For example, if you specify "type": "string" for a field, Copilot will not output a number or boolean for that field. If you list a field in the "required" array, Copilot will always include it. This behavior makes the output predictable for downstream systems.

Steps to Generate Strict JSON Schema Output with Copilot

  1. Open the Copilot pane in your Microsoft 365 app
    Click the Copilot icon in the ribbon or press Alt+Shift+I to open the side pane. This works in Word, Excel, Outlook, and Teams.
  2. Write the base instruction
    Type: “Output a JSON object with the following schema. Do not include any text outside the JSON object.” This prevents Copilot from adding Markdown code fences or extra sentences.
  3. Define the schema inline
    After the instruction, paste your JSON Schema definition. Example: {"type":"object","properties":{"name":{"type":"string"},"age":{"type":"integer"}},"required":["name","age"],"additionalProperties":false}
  4. Add the data request
    Write: “Generate data for a new employee record.” This tells Copilot what values to fill in. Without this, Copilot may ask for clarification or output an empty schema.
  5. Press Enter or click Send
    Copilot returns a JSON object that matches your schema exactly. Example: {"name":"Sarah Chen","age":32}
  6. Validate the output
    Copy the JSON into a validator like JSONLint or your API testing tool. Check that no extra fields exist and that all required fields are present.

ADVERTISEMENT

Common Schema Definition Mistakes and How to Avoid Them

Copilot adds extra fields that break my API contract

The most frequent problem is Copilot outputting fields you did not define. For example, you request {"name":"string","email":"string"} and Copilot adds "id":123 or "status":"active". To prevent this, include "additionalProperties": false in your schema. This tells Copilot to reject any field not listed in the properties object.

Copilot wraps the JSON in a Markdown code block

By default, Copilot returns JSON inside a Markdown code block with triple backticks. If your API parser expects raw JSON, this causes a parse error. Add the instruction: “Do not use Markdown code fences. Output only the JSON object.” If Copilot still adds fences, append the prompt with: “If you wrap the JSON in backticks, I will reject the output.” This negative reinforcement often works.

Copilot outputs a string instead of an integer for a numeric field

When you define "age": {"type": "integer"}, Copilot should output "age": 32, not "age": "32". But sometimes Copilot treats all values as strings. To enforce the type, add "coerce": true in the schema if your Copilot version supports it, or explicitly state: “The field ‘age’ must be a number, not a string.” You can also add an example: "age": 30 inside the schema’s examples property.

Copilot Output Modes: Structured vs Free-Form

Item Structured JSON Output Free-Form Text Output
Output format JSON object with exact schema Natural language or Markdown
Use case API ingestion, data pipelines, automation Human reading, summaries, drafts
Schema enforcement Yes — via JSON Schema in prompt No — Copilot decides structure
Error handling Predictable — parser can validate Unpredictable — requires human review
Prompt complexity Higher — must define schema inline Lower — simple question or request

For API use, always choose structured JSON output. The upfront effort of writing the schema pays off with zero manual cleanup. Free-form output is better for exploratory questions or when you need Copilot to decide the structure.

Advanced Prompt Template for Complex Schemas

For nested objects and arrays, extend the schema definition. Example prompt for an employee with multiple addresses:

Output a JSON object with this schema: {"type":"object","properties":{"employee":{"type":"object","properties":{"name":{"type":"string"},"department":{"type":"string"},"addresses":{"type":"array","items":{"type":"object","properties":{"street":{"type":"string"},"city":{"type":"string"},"zip":{"type":"string"}},"required":["street","city"],"additionalProperties":false}}},"required":["name","department"],"additionalProperties":false}} Generate a record for a new hire in the engineering department.

Copilot outputs a JSON object with nested employee and addresses arrays, all respecting the schema. Test this with a validator to confirm no extra fields appear.

Additional Resources

For more control, combine the JSON schema prompt with Copilot’s built-in structured output modes in Microsoft 365 Copilot Studio. You can define a custom action that enforces the schema server-side. This is useful when you cannot modify prompts per request. Also consider using the Copilot Graph API with a response_format parameter set to json_object for programmatic access. This bypasses the Copilot pane entirely and returns raw JSON directly to your application.

ADVERTISEMENT