AI・機械学習
中級

JSONスキーマによるツール定義(ジェイソンスキーマによるツールていぎ)

LLMのFunction CallingやTool Useで使用するツール仕様記述形式。JSON Schema標準に基づき、関数名・説明・引数の型・必須フィールドを定義し、モデルが正確な呼び出し引数を生成できるようにする。

0 回閲覧
0 いいね
2026/6/6 更新
関連タグ
json-schema
tool-definition
function-calling
schema-design
api-design

JSONスキーマによるツール定義とは

LLMのFunction CallingやTool Useでは、利用可能なツールをJSON Schema形式で定義する。このスキーマがモデルの「説明書」となり、いつどのツールを、どんな引数で呼び出すかを決定する。

基本構造

{
  "type": "function",
  "function": {
    "name": "create_calendar_event",
    "description": "Googleカレンダーに新しいイベントを作成する。日時・場所・参加者を指定できる。",
    "parameters": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string",
          "description": "イベントのタイトル(必須・最大100文字)"
        },
        "start_datetime": {
          "type": "string",
          "description": "開始日時(ISO 8601形式: 2025-06-06T14:00:00+09:00)"
        },
        "duration_minutes": {
          "type": "integer",
          "description": "イベントの長さ(分)",
          "minimum": 5,
          "maximum": 1440
        },
        "location": {
          "type": "string",
          "description": "場所またはMeetingリンク(省略可)"
        },
        "attendees": {
          "type": "array",
          "items": {"type": "string", "format": "email"},
          "description": "招待するメールアドレスのリスト"
        },
        "recurrence": {
          "type": "string",
          "enum": ["none", "daily", "weekly", "monthly"],
          "description": "繰り返し設定",
          "default": "none"
        }
      },
      "required": ["title", "start_datetime", "duration_minutes"]
    }
  }
}

主要なJSONスキーマ型とLLM活用

プリミティブ型

型JSON Schema用途例
文字列"type": "string"検索クエリ・名前
整数"type": "integer"カウント・ページ番号
数値"type": "number"価格・座標
真偽値"type": "boolean"フラグ設定
配列"type": "array"複数値リスト
オブジェクト"type": "object"構造化データ

enum制約(精度向上に効果的)

"status": {
  "type": "string",
  "enum": ["pending", "active", "completed", "cancelled"]
}

format指定

"email": {"type": "string", "format": "email"},
"date": {"type": "string", "format": "date"},
"uri": {"type": "string", "format": "uri"}

descriptionフィールドの重要性

descriptionは最もモデルの精度に影響する。

悪い例:

"name": "search",
"description": "検索する"

良い例:

"name": "search_products",
"description": "商品データベースを検索する。価格帯・カテゴリ・ブランドで絞り込み可能。在庫のある商品のみ返す。最大100件。"

プロバイダー別の微妙な違い

プロバイダースキーマキーadditionalProperties対応バージョン
OpenAIparametersfalse推奨Draft 7
Anthropicinput_schema制限なしDraft 7
Google Geminiparameters制限なし独自拡張あり

Strict Mode(OpenAI)

OpenAI APIのstrict: trueオプション:

  • スキーマ定義に完全準拠した引数生成を保証
  • additionalProperties: falseが必須
  • requiredに全プロパティを含める必要あり
  • モデルが定義外の引数を生成しない安全モード
この記事について
カテゴリーAI・機械学習
難易度中級
作成日2026/6/6