Query business scenarios

更新时间:
复制 MD 格式

Use the AI Guardrails SDK for Python to list all existing and custom business scenarios. This is typically the first step before creating a new business scenario, so you can choose an existing configuration to import.

Prerequisites

Before you begin, ensure that you have:

  • Python dependencies installed. See Installation for the required Python version. Using a different version causes operation calls to fail.

  • The Extension.Uploader utility class downloaded and imported into your project.

  • A RAM user AccessKey ID and AccessKey secret with permission to call the Content Moderation API.

Set up credentials

Store your credentials as environment variables to avoid hardcoding sensitive information in your code.

export ALIBABA_CLOUD_ACCESS_KEY_ID='<your-access-key-id>'
export ALIBABA_CLOUD_ACCESS_KEY_SECRET='<your-access-key-secret>'
Important

Never hardcode your AccessKey ID or AccessKey secret directly in source code. Always load credentials from environment variables or a secrets manager.

Query business scenarios

Call DescribeUserBizTypes to retrieve all business scenarios — both system defaults and custom ones.

Supported regions

Region IDLocation
cn-shanghaiChina (Shanghai)
cn-beijingChina (Beijing)
cn-shenzhenChina (Shenzhen)
ap-southeast-1Singapore

Sample code

Reuse the client instance across requests to improve performance and avoid repeated connection overhead.

# coding=utf-8

import os
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20170823 import DescribeUserBizTypesRequest

# Initialize the client once and reuse it across requests.
# Reusing the client improves moderation performance and avoids repeated connections.
clt = client.AcsClient(
    os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
    os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
    "cn-shanghai"
)
region_provider.modify_point('Green', "cn-shanghai", 'green.cn-shanghai.aliyuncs.com')

request = DescribeUserBizTypesRequest.DescribeUserBizTypesRequest()
request.set_accept_format('JSON')

response = clt.do_action_with_exception(request)
print(response)

Response

A successful request returns a JSON object with the following structure:

{
  "RequestId": "ADDBDECA-E1B2-4988-AE3B-956BF51573EC",
  "BizTypeList": [
    {
      "BizType": "mohongtest2",
      "Source": "custom",
      "CiteTemplate": false,
      "IndustryInfo": ""
    }
  ],
  "BizTypeListImport": [
    {
      "BizType": "mohongtest2",
      "Source": "custom",
      "CiteTemplate": false,
      "IndustryInfo": ""
    }
  ]
}

Response fields

FieldTypeDescription
RequestIdStringThe request ID.
BizTypeListArrayThe business scenarios in your account.
BizTypeListImportArrayThe business scenarios available for import when creating a new business scenario.
BizTypeStringThe name of the business scenario.
SourceStringThe origin of the scenario. Valid values: custom (user-created) or system (AI Guardrails default).
CiteTemplateBooleanSpecifies whether the scenario was created from an industry template.
IndustryInfoStringThe industry information associated with the scenario.

What's next

  • To create a business scenario and import a configuration from BizTypeListImport, see Create a business scenario.

  • To update or delete an existing scenario, see Manage business scenarios.