Learning resourcesReviewed · Perplexity

Perplexity Agent API: Structure the output

This guide teaches developers to request predictable JSON from Perplexity's Agent API, but responses cut short may break the requested structure. It demonstrates JSON Schema configuration, Python validation with Pydantic and a cURL request.

Researched 25 Nov 2026

In short.

This guide helps developers make Perplexity Agent API responses fit a defined JSON structure, but it leaves handling of responses cut short to a separate reference. It demonstrates schema configuration and Python validation, although the Python and cURL examples impose different field requirements. The page also warns that links generated inside JSON can be malformed or fabricated. Pricing, licensing and measured reliability are not established.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete page at [https://docs.perplexity.ai/docs/agent-api/building-agents/shape-output.md], both code examples, the schema-reinforcement tip, URL warning, documentation-index notice and next-step references. Linked content is excluded, including the documentation index [https://docs.perplexity.ai/llms.txt], Output Control [https://docs.perplexity.ai/docs/agent-api/output-control.md] and Keep context [https://docs.perplexity.ai/docs/agent-api/building-agents/keep-context.md]. Nothing was executed. Actual schema adherence, factual accuracy, model availability, costs and reuse rights remain unverified or unknown.

The overview

identity

Structure the output is a Perplexity Agent API documentation guide at [https://docs.perplexity.ai/docs/agent-api/building-agents/shape-output.md]. It teaches one API feature: requesting JSON that follows a developer-defined schema. The resource is a guide, rather than an SDK, model or standalone application.

assessment

The page is useful as a focused introduction to passing generated data into application code. It supplies a concrete request configuration and a Python validation step. Installation, schema compatibility and recovery from incomplete generation require information beyond this page; production reliability is not assessed.

users

The guide fits developers building applications that consume defined fields, such as a company's name, sector and headquarters. Beginners receive short examples but need some familiarity with API requests and JSON. Experienced developers can inspect the schema configuration and validation approach, although the page provides no exhaustive compatibility reference.

capabilities

The documented feature lets a request specify field names, types and required fields through JSON Schema, a description of the structure valid data must follow. The Python example generates that schema from a Pydantic model and validates response.output_text. The cURL example shows a direct HTTP request and pipes its response to jq; it does not demonstrate validation against the company schema.

Using it

requirements

The HTTP example uses an API credential supplied through PERPLEXITY_API_KEY, curl and jq. The Python example imports the perplexity SDK and Pydantic. The page supplies no installation commands, package versions or account setup instructions.

Both requests name openai/gpt-5.6-sol as the model. The page does not establish its current availability or which other models support the same configuration.

mechanism

Set response_format.type to json_schema and provide a json_schema object containing name and schema. The guide states that response text conforms to the schema unless generation is cut short. In Python, CompanySummary.model_validate_json then parses and validates response.output_text.

The page recommends reinforcing the requested schema in the prompt. It does not explain the server-side enforcement mechanism or enumerate supported JSON Schema keywords.

setup

For the Python approach, define a Pydantic model, obtain its schema with model_json_schema, and pass that schema to client.responses.create alongside the model and input. The example overrides required to include every model field and sets additionalProperties to false, which disallows extra keys. Validate the returned output_text with the same Pydantic model.

The HTTP alternative posts the input and schema to [https://api.perplexity.ai/v1/agent] with bearer authentication and a JSON content type. Credential configuration for the Python client is not explained.

example

Both examples ask for an NVIDIA summary containing name, sector, headquarters and key_products. No generated response or factual result is shown.

The examples specify different constraints. Python requires every field, including key_products, whose optional type permits a null value, and prohibits extra keys. The cURL schema requires only name, sector and headquarters; key_products may be omitted, must be an array when present, and has no null option. It also omits the additionalProperties restriction. Choose the intended behavior before treating the examples as interchangeable.

Assessment & evidence

limitations

Generation cut short can prevent schema conformity. This page does not show how to detect that condition, handle validation failures or retry a request.

The guide warns that requesting links inside structured JSON can produce malformed or fabricated URLs. It directs developers to citations or search_results items in the response output instead, but does not demonstrate those items' structure.

reasoning

Defined fields and types reduce the need to extract data from free-form prose. Pydantic validation provides a way to check whether returned data fits the application model. These checks concern structure; they do not establish that a company's sector, headquarters or products are factually correct.

The page supplies no measured adherence rates, benchmarks or latency comparisons. Its claims describe intended behavior rather than demonstrated reliability.

alternatives

The page contrasts structured output with the API's default free-form text response. Free-form text can suit direct reading, while software consuming specific fields benefits from a defined structure. Python with Pydantic and direct HTTP requests are the two illustrated implementation approaches. Competing services and libraries are not compared.

evidence

The evidence consists of the complete Perplexity documentation page, including its Python and cURL examples, schema-reinforcement tip, URL warning and references to further documentation. It contains no execution logs, returned company summary or independent measurements. No code or API request was executed.

Access & freshness

costs

The page provides no API prices, token rates, free-tier terms or example request costs. The cost of using this feature is unknown from the supplied evidence.

rights

The supplied page states no license or reuse terms for its text or code examples. Permission to copy, modify or redistribute those materials is unknown from this evidence.

freshness

The page was captured on 25 November 2026. The supplied text contains no publication date, update date or SDK version requirements. Current model availability and compatibility were not independently verified.

actions

Define which fields must be present, which may be null and whether extra keys are allowed. Resolve the differences between the Python and cURL schemas before adopting either example. Validate returned data and define handling for responses cut short.

Use the documented citations or search_results items for source links. The page points to Output Control [https://docs.perplexity.ai/docs/agent-api/output-control.md] for streaming, background runs, error handling and further examples; that linked reference was not assessed.

Evidence for this report

selected-page.txtselected · checked 2026-11-25