iflytek/astron-agent · error · ValueError

无效的年龄组参数: ,有效选项

Error message

无效的年龄组参数: {group},有效选项: {valid_groups}

What it means

The ISE (Intelligent Speech Evaluation) client constructor validates the age group parameter before building the request. Only 'pupil', 'youth', and 'adult' are supported engine profiles, so any other value raises a ValueError immediately at object creation.

Solutions

  1. Pass exactly one of 'pupil', 'youth', 'adult' as the group parameter
  2. Normalize/validate caller-supplied input against the allowed list before constructing the client
  3. Add a mapping layer from your app's own age categories to the supported values

Example fix

// before
client = IseClient(group='child', audio_data=audio, text=text, language='en')
// after
mapping = {'child': 'pupil', 'teen': 'youth', 'grown-up': 'adult'}
group = mapping.get(user_group, user_group)
if group not in ('pupil', 'youth', 'adult'):
    raise ValueError(f'unsupported group: {group}')
client = IseClient(group=group, audio_data=audio, text=text, language='en')
Defensive patterns

Strategy: validation

Validate before calling

VALID_GROUPS = ('pupil', 'youth', 'adult')
if group not in VALID_GROUPS:
    raise ValueError(f'group must be one of {VALID_GROUPS}, got {group!r}')

Try / catch

try:
    client = IseClient(group=group, audio_data=audio, text=text, language=lang)
except ValueError as e:
    log.error('invalid ISE group: %s', e)
    group = 'adult'
    client = IseClient(group=group, audio_data=audio, text=text, language=lang)

Prevention

When it happens

Trigger: Calling the ISE client __init__ with group set to anything other than 'pupil'/'youth'/'adult' — e.g. passing a localized label, None, or an empty string.

Common situations: Mapping an end-user-facing age selection (Chinese labels, numbers like 'child') directly to the API parameter; forgetting to normalize user input to one of the three enum-like strings.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/dce5a8af95370a86. Report an issue: GitHub.

Appendix: source

Thrown at core/plugin/aitools/service/ise/ise_client.py:347

        app_id: str,
        api_key: str,
        api_secret: str,
        audio_data: bytes,
        text: str = "",
        language: str = "cn",
        category: str = "read_sentence",
        group: str = "adult",
    ):
        self.app_id = app_id
        self.api_key = api_key
        self.api_secret = api_secret
        self.audio_data = audio_data
        self.text = text

        # Validate the age group parameter.
        valid_groups = ["pupil", "youth", "adult"]
        if group not in valid_groups:
            raise ValueError(f"无效的年龄组参数: {group},有效选项: {valid_groups}")

        # Set up the engine type parameter.
        ent = "cn_vip" if language == "cn" else "en_vip"

        # Set up the public parameters.
        self.common_args = {"app_id": self.app_id}

        # Business parameters - according to the official document format
        self.business_args = {
            "category": category,  # Evaluation category
            "sub": "ise",  # Service type
            "ent": ent,  # Engine type
            "cmd": "ssb",  # Command
            "auf": "audio/L16;rate=16000",  # Audio format
            "aue": "raw",  # Audio encoding
            "text": self._encode_text() if text else "",  # Evaluation text
            "tte": "utf-8",  # Text encoding
            "rstcd": "utf8",  # Result encoding

View on GitHub (pinned to 5e758547a8)