All Products
Search
Document Center

AI Guardrails:Delete a person from a group

Last Updated:Mar 31, 2026

Use the Content Moderation Python SDK to remove a person from a group. This operation unbinds the person from the group — it does not delete the person's information or images.

For parameter details, see API operation for deleting a person from a group.

Prerequisites

Before you begin, ensure that you have:

  • Installed the Python dependencies using the required Python version described in Installation. Using a different Python version causes subsequent API calls to fail.

  • Downloaded the Extension.Uploader utility class and imported it into your project

  • A Content Moderation API endpoint. For available endpoints, see Endpoints

Remove a person from a group

Replace personId with the ID of the person to remove, and groupIds with the list of groups to remove the person from.

# coding=utf-8
# Delete a person from a specified group.

import json
import os

from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import DeleteGroupsRequest

# Reuse the client instance across requests to improve performance
# and avoid repeated connection overhead.
# Get the AccessKey ID and secret of your RAM user from environment variables.
clt = client.AcsClient(
    os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
    os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
    "cn-shanghai"
)

region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')

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

request.set_content(
    bytearray(
        json.dumps({"personId": "python_personId_test_1", "groupIds": ["python_groupId_1"]}),
        "utf-8"
    )
)

response = clt.do_action_with_exception(request)
result = json.loads(response)

if result["code"] == 200:
    result_object = result["data"]
    if result_object["code"] == 200:
        person_id = result_object["personId"]
        print(person_id)
Note

The request succeeds when both result["code"] and result["data"]["code"] equal 200. The response returns the personId of the unbound person.

What's next