HKUDS/Vibe-Trading · error · ValueError

broker must not be blank

Error message

broker must not be blank

What it means

connector_profile_id_for_broker resolves the preferred connector profile id for a broker on-ramp. It normalizes the broker argument (strip + lower) and immediately rejects empty/whitespace-only/None input with ValueError('broker must not be blank'), since there is no meaningful profile lookup without a broker key.

Source

Thrown at agent/src/trading/service.py:1141

    key = str(broker or "").strip().lower()
    if not key:
        return None
    for profile in list_profiles():
        if profile.connector == key and profile_supports_live_runner(profile):
            return profile
    return None


def broker_supports_live_runner(broker: str) -> bool:
    """Return whether any configured profile exposes live runner management."""
    return live_runner_profile_for_broker(broker) is not None


def connector_profile_id_for_broker(broker: str) -> str:
    """Return the preferred connector profile id for a broker on-ramp."""
    key = str(broker or "").strip().lower()
    if not key:
        raise ValueError("broker must not be blank")

    candidates = [profile for profile in list_profiles() if profile.connector == key and profile.environment == "live"]
    for profile in candidates:
        if profile.transport == "remote_mcp":
            return profile.id
    if candidates:
        return candidates[0].id
    return f"{key}-live-mcp"


def runner_tool_name(connector: str, operation: str) -> str | None:
    """Map a runner operation to a connector-specific remote MCP tool name."""
    if connector == "robinhood":
        from src.trading.connectors.robinhood.mcp import runner_tool_name as _runner_tool_name

        return _runner_tool_name(operation)
    return None

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Pass a non-empty broker identifier such as 'alpaca' or 'ibkr'
  2. Validate and normalize the broker field at the API boundary (request schema) before calling this function
  3. Default missing broker values from config explicitly and fail with a user-facing validation message

Example fix

# before
profile_id = connector_profile_id_for_broker(request.broker)  # request.broker may be ''

# after
broker = (request.broker or '').strip().lower()
if not broker:
    raise HTTPException(status_code=422, detail="broker is required")
profile_id = connector_profile_id_for_broker(broker)
Defensive patterns

Strategy: validation

Validate before calling

def normalize_broker(broker):
    key = str(broker or "").strip().lower()
    if not key:
        raise ValueError("broker is required")
    return key

profile_id = connector_profile_id_for_broker(normalize_broker(request.broker))

Type guard

def is_valid_broker(broker) -> bool:
    return bool(str(broker or "").strip())

Prevention

When it happens

Trigger: Calling connector_profile_id_for_broker('') , connector_profile_id_for_broker(' '), or connector_profile_id_for_broker(None) — e.g. live_authorize_endpoint forwarding an unvalidated request field or an unset config/env value.

Common situations: An API request body where the broker field is missing or blank, form input not validated upstream, environment variable for the broker not set, or a caller passing broker=None as a default.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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