> ## Documentation Index
> Fetch the complete documentation index at: https://docs.waffo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# プロンプトのスキャン

> 生成前に生成プロンプトのコンテンツセーフティをチェックする

製品が画像や動画を生成する前に、ユーザーのテキストプロンプトに対して Waffo コンテンツセーフティチェックを実行します。レスポンスは `action` フィールドに判定を保持し、それが `allow` の場合にのみ生成に進みます。このチェックはステートレスで、返却後にプロンプト本文を保持しません。

```
POST /v1/actions/verification/scan-prompt
```

**認証：** API Key

## リクエストボディ

| フィールド      | 型      | 必須  | 説明                                                 |
| ---------- | ------ | --- | -------------------------------------------------- |
| `prompt`   | string | Yes | ユーザーの生成プロンプト（1-10000 文字）                           |
| `locale`   | string | No  | チェックの言語ヒント —— `ja`、`en`、`zh` のいずれか                 |
| `semantic` | string | No  | セマンティックスコアリングモード —— `off`、`shadow`、`enforce` のいずれか |

<Note>
  `semantic` はオプションのセマンティックスコアリング層を制御します：`off` は無効化、`shadow` は判定に影響を与えずにスコアリング、`enforce` はスコアを判定に反映させます。省略した場合、サービスはデフォルトモードを適用します。
</Note>

## リクエスト例

<CodeGroup>
  ```typescript SDK theme={"system"}
  import { WaffoPancake } from "@waffo/pancake-ts";

  const client = new WaffoPancake({
    merchantId: process.env.WAFFO_MERCHANT_ID!,
    privateKey: process.env.WAFFO_PRIVATE_KEY!,
  });

  const { data } = await client.contentSafety.scanPrompt({
    prompt: "A serene mountain landscape at sunset",
    locale: "en",
    semantic: "enforce",
  });

  if (data.action === "allow") {
    // safe to generate
  }
  ```

  ```typescript TypeScript (fetch) theme={"system"}
  // Uses callApi() helper from authentication.mdx
  const result = await callApi("POST", "/v1/actions/verification/scan-prompt", {
    prompt: "A serene mountain landscape at sunset",
    locale: "en",
    semantic: "enforce",
  });
  console.log(result.data.action);     // => "allow"
  console.log(result.data.reasonCode); // => "allowed"
  ```

  ```java Java theme={"system"}
  // Uses callApi() helper from authentication.mdx
  String body = """
      {"prompt":"A serene mountain landscape at sunset","locale":"en","semantic":"enforce"}""";

  String response = callApi("POST", "/v1/actions/verification/scan-prompt", body);
  System.out.println(response);
  // => {"data":{"action":"allow","reasonCode":"allowed","matchedCategories":[],...}}
  ```

  ```python Python theme={"system"}
  # Uses call_api() helper from authentication.mdx
  result = call_api("POST", "/v1/actions/verification/scan-prompt", {
      "prompt": "A serene mountain landscape at sunset",
      "locale": "en",
      "semantic": "enforce",
  })
  data = result["data"]
  print(data["action"])     # => "allow"
  print(data["reasonCode"]) # => "allowed"
  ```

  ```go Go theme={"system"}
  // Uses callAPI() helper from authentication.mdx
  body := map[string]interface{}{
      "prompt":   "A serene mountain landscape at sunset",
      "locale":   "en",
      "semantic": "enforce",
  }
  result, err := callAPI("POST", "/v1/actions/verification/scan-prompt", body)
  if err != nil {
      log.Fatal(err)
  }
  fmt.Println(string(result))
  // => {"data":{"action":"allow","reasonCode":"allowed","matchedCategories":[],...}}
  ```

  ```rust Rust theme={"system"}
  // Uses call_api() helper from authentication.mdx
  let body = serde_json::json!({
      "prompt": "A serene mountain landscape at sunset",
      "locale": "en",
      "semantic": "enforce"
  });
  let result = call_api("POST", "/v1/actions/verification/scan-prompt", &body).await?;
  println!("{}", result);
  // => {"data":{"action":"allow","reasonCode":"allowed","matchedCategories":[],...}}
  ```

  ```c C theme={"system"}
  /* Uses call_api() helper from authentication.mdx */
  const char *body = "{\"prompt\":\"A serene mountain landscape at sunset\",\"locale\":\"en\",\"semantic\":\"enforce\"}";
  char *response = call_api("POST", "/v1/actions/verification/scan-prompt", body);
  printf("%s\n", response);
  free(response);
  ```

  ```cpp C++ theme={"system"}
  // Uses callApi() helper from authentication.mdx
  std::string body = R"({"prompt":"A serene mountain landscape at sunset","locale":"en","semantic":"enforce"})";
  std::string response = callApi("POST", "/v1/actions/verification/scan-prompt", body);
  std::cout << response << std::endl;
  // => {"data":{"action":"allow","reasonCode":"allowed","matchedCategories":[],...}}
  ```

  ```bash cURL theme={"system"}
  MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
  TIMESTAMP=$(date +%s)
  BODY='{"prompt":"A serene mountain landscape at sunset","locale":"en","semantic":"enforce"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/verification/scan-prompt
  $TIMESTAMP
  $BODY_HASH"

  SIGNATURE=$(echo -n "$CANONICAL_REQUEST" | openssl dgst -sha256 -sign private_key.pem | base64 -w 0)

  curl -X POST "https://api.waffo.ai/v1/actions/verification/scan-prompt" \
    -H "Content-Type: application/json" \
    -H "X-Merchant-Id: $MERCHANT_ID" \
    -H "X-Timestamp: $TIMESTAMP" \
    -H "X-Signature: $SIGNATURE" \
    -d "$BODY"
  ```

  ```bash wget theme={"system"}
  MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
  TIMESTAMP=$(date +%s)
  BODY='{"prompt":"A serene mountain landscape at sunset","locale":"en","semantic":"enforce"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/verification/scan-prompt
  $TIMESTAMP
  $BODY_HASH"

  SIGNATURE=$(echo -n "$CANONICAL_REQUEST" | openssl dgst -sha256 -sign private_key.pem | base64 -w 0)

  wget -qO- "https://api.waffo.ai/v1/actions/verification/scan-prompt" \
    --header="Content-Type: application/json" \
    --header="X-Merchant-Id: $MERCHANT_ID" \
    --header="X-Timestamp: $TIMESTAMP" \
    --header="X-Signature: $SIGNATURE" \
    --post-data="$BODY"
  ```
</CodeGroup>

## 成功レスポンス (200)

```json theme={"system"}
{
  "data": {
    "action": "allow",
    "reasonCode": "allowed",
    "matchedCategories": [],
    "requestId": "REQ_2aUyqjCzEIiEcYMKj7TZtw",
    "semanticStatus": "scored"
  }
}
```

## レスポンスフィールド

| フィールド               | 型         | 説明                                                                              |
| ------------------- | --------- | ------------------------------------------------------------------------------- |
| `action`            | string    | 判定：`allow`、`review`、または `block`。`allow` の場合にのみ生成に進む。                            |
| `reasonCode`        | string    | 機械可読の理由：`allowed`、`review_required`、`restricted_content`、または `service_degraded` |
| `matchedCategories` | string\[] | プロンプトが一致した制限カテゴリ。判定が `allow` の場合は空                                              |
| `requestId`         | string    | このチェックの識別子。異議申し立てでリクエストを参照する際に付与する                                              |
| `semanticStatus`    | string    | セマンティックスコアリング層の状態：`disabled`、`scored`、`shadow_scored`、`provider_error` など       |

## 判定への対応

| `action` | 推奨される処理                                                 |
| -------- | ------------------------------------------------------- |
| `allow`  | 通常どおり生成モデルを呼び出す。                                        |
| `review` | リクエストを保留し、後でリトライする。通常は約1時間以内に結果が出る。                     |
| `block`  | 生成しない。「このコンテンツは当社の利用ガイドラインに適合しません」などのフレンドリーなメッセージを表示する。 |

<Note>
  モデレーションサービスが一時的に利用できない場合、チェックは `action: "review"` を `reasonCode: "service_degraded"` 付きで返し、判定なしで何も生成されないようにします。デグレード応答を受け取った場合は、生成せずにリクエストをリトライしてください。
</Note>

## エラー

> **リトライポリシー**：4xx は一切リトライしない — リクエストを修正してから再送信。5xx は指数バックオフでリトライ（5s 開始、最大 3 回）。

| ステータス | `errors[0].message`                                           | 意味                          | 推奨処理                           |
| ----- | ------------------------------------------------------------- | --------------------------- | ------------------------------ |
| 400   | `Missing required field: prompt`                              | リクエストボディに `prompt` が含まれていない | 入力を修正して再送信。                    |
| 400   | `Prompt cannot be empty or contain only whitespace`           | トリム後の `prompt` が空           | 入力を修正して再送信。                    |
| 400   | `Prompt cannot exceed 10000 characters`                       | `prompt` が 10000 文字を超える     | プロンプトを短縮して再送信。                 |
| 400   | `Invalid locale. Must be one of: ja, en, zh`                  | `locale` がサポートされている値ではない    | サポートされている `locale` を使って再送信。    |
| 400   | `Invalid semantic mode. Must be one of: off, shadow, enforce` | `semantic` がサポートされている値ではない  | サポートされている `semantic` 値を使って再送信。 |

<Note>
  生成前にプロンプトをチェックし、`allow` の場合にのみ続行してください。完全なカバレッジには、[AIGC コンプライアンス](/ja/mor/account-reviews/aigc-compliance)に記載のとおり生成後段階のチェックを追加してください。
</Note>
