構造化出力プレイグラウンド

モデルAPIを呼び出さずに、スキーマ制約付きのJSONサンプルを検証し、プロバイダー別のリクエストパターンをコピーします。

構造化出力ワークベンチ
例のプリセット
検証結果

5 件の問題が見つかりました。

パス $.price
問題 必須フィールドがありません。
パス $.extra
問題 予期しないフィールドです。
パス $.attributes[0].rank
問題 予期しないフィールドです。
パス $.in_stock
問題 boolean を期待しましたが、string を受け取りました。
パス $.sku
問題 string を期待しましたが、number を受け取りました。
プロバイダーパターン
プロバイダー非依存プロンプト
目標のJSON構造を契約として使い、余分なキーを拒否してください。
Return JSON only.
Use the target JSON structure as the contract for keys, nesting, arrays, and value types.
Do not wrap the result in markdown.
Do not add extra keys.

Target structure:
{
  "sku": "abc-123",
  "price": 19.99,
  "in_stock": true,
  "attributes": [
    {
      "name": "color",
      "value": "blue"
    }
  ]
}
OpenAI Responses API
text.format と厳格な JSON スキーマを使って、直接の構造化出力を要求します。
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-5",
    input="Return the response in the required JSON shape.",
    text={
        "format": {
            "type": "json_schema",
            "name": "structured_output",
            "strict": True,
            "schema": {
              "type": "object",
              "properties": {
                "sku": {
                  "type": "string"
                },
                "price": {
                  "type": "number"
                },
                "in_stock": {
                  "type": "boolean"
                },
                "attributes": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "value": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "name",
                      "value"
                    ],
                    "additionalProperties": false
                  }
                }
              },
              "required": [
                "sku",
                "price",
                "in_stock",
                "attributes"
              ],
              "additionalProperties": false
            },
        }
    },
)

print(response.output_text)
Anthropic プロンプトパターン
目標構造をそのまま貼り付け、モデルに JSON のみで回答するよう指示してください。
You are returning structured data for a downstream parser.
Output JSON only.
Match the exact keys, nesting, and value types shown below.
If a field is unknown, return a valid placeholder of the same type.

Target structure:
{
  "sku": "abc-123",
  "price": 19.99,
  "in_stock": true,
  "attributes": [
    {
      "name": "color",
      "value": "blue"
    }
  ]
}