HKUDS/Vibe-Trading · error · ValueError

connection label must contain 1 to 80 printable characters

Error message

connection label must contain 1 to 80 printable characters

What it means

Raised when a connection's label (falling back to the profile's default label) is empty after stripping, longer than 80 characters, or contains control characters (any codepoint < 32). Labels are meant to be short human-readable printable names.

Source

Thrown at agent/src/trading/connections.py:319

        """
        if not isinstance(raw, dict):
            raise ValueError("each local connection must be an object")
        connection_id = str(raw.get("id") or "").strip().lower()
        if not _ID_RE.fullmatch(connection_id):
            raise ValueError(f"invalid local connection id: {connection_id or '?'}")
        profile_id = str(raw.get("profile_id") or "").strip().lower()
        profile = profile_by_id(profile_id)
        if not is_portfolio_connection_profile(profile):
            raise ValueError(
                f"connection profile is not eligible for read-only portfolios: {profile_id}"
            )
        label = str(raw.get("label") or profile.label).strip()
        if (
            not label
            or len(label) > 80
            or any(ord(character) < 32 for character in label)
        ):
            raise ValueError(
                "connection label must contain 1 to 80 printable characters"
            )
        expected_ref = _credential_reference(profile.id, connection_id)
        credential_ref = str(raw.get("credential_ref") or expected_ref)
        if (
            credential_ref == CredentialStore.reference(connection_id)
            and profile.transport != "local_plugin"
        ):
            credential_ref = expected_ref
        if credential_ref != expected_ref:
            raise ValueError(
                "connection credential_ref does not match its local transport"
            )
        return TradingConnection(
            id=connection_id,
            profile_id=profile.id,
            label=label,
            credential_ref=credential_ref,

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Set label to 1-80 printable characters, trimmed of leading/trailing whitespace
  2. Strip control characters (tabs/newlines) from the label before saving
  3. Omit label entirely so the profile's default label is used, if that default is valid
  4. Add a UI-side maxlength=80 and printable-character filter on the label field

Example fix

// before
{"id": "alpaca", "profile_id": "paper", "label": "\t  \n"}

// after
{"id": "alpaca", "profile_id": "paper", "label": "Alpaca paper trading"}
Defensive patterns

Strategy: validation

Validate before calling

def valid_label(label: str) -> bool:
    label = label.strip()
    return 0 < len(label) <= 80 and all(ord(c) >= 32 for c in label)

Type guard

def is_valid_connection_label(value: object) -> bool:
    return isinstance(value, str) and valid_label(value)

Try / catch

try:
    store.create(connection_id, profile_id, label)
except ValueError as exc:
    if "1 to 80 printable" in str(exc):
        label = "".join(c for c in label if ord(c) >= 32).strip()[:80] or profile.label
        store.create(connection_id, profile_id, label)
    else:
        raise

Prevention

When it happens

Trigger: A settings entry with "label": " ", a label over 80 chars, or one containing tab/newline/control characters (raw.get("label") empty AND profile.label also empty triggers it too). Hit during _parse from list() or save().

Common situations: Whitespace-only labels from form input or env vars; pasting a long descriptive string as a label; labels containing newline or tab characters from spreadsheet/CSV imports; a profile with an empty default label and no explicit override.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/8ca35f48bbd50c6e. Report an issue: GitHub.