HKUDS/Vibe-Trading · error · ValueError

{field} must be an integer, got {value!r}

Error message

{field} must be an integer, got {value!r}

What it means

The shadow_account tool's _int_arg helper converts a kwarg to int and raises ValueError when conversion fails. None and "" fall back to a default; anything else that int() cannot parse (TypeError/ValueError/OverflowError) produces this error naming the field and offending value. It's an input validation guard on integer parameters.

Source

Thrown at agent/src/tools/shadow_account_tool.py:62

    Args:
        value: Raw argument value; ``None`` and ``""`` mean "not supplied".
        field: Argument name, used in the error message.
        default: Value to use when the argument was not supplied.

    Returns:
        The requested integer, or ``default`` when the argument was absent.

    Raises:
        ValueError: If the value is present but not an integer. Only an absent
            value may fall back to the default — silently replacing a malformed
            explicit value would answer a different question than was asked.
    """
    if value is None or value == "":
        return default
    try:
        return int(value)
    except (TypeError, ValueError, OverflowError):
        raise ValueError(f"{field} must be an integer, got {value!r}") from None


def _validate_optional_journal_path(raw: Any) -> str | None:
    """Validate a journal_path kwarg that may be missing/empty.

    Returns the resolved path string, or None when the caller didn't pass
    one. Raises ValueError (already the contract of `safe_user_path`) when
    the path escapes the user envelope.
    """
    if not raw:
        return None
    return str(safe_user_path(raw))


# ---------------- Tool 1: extract ----------------

class ExtractShadowStrategyTool(BaseTool):
    """Extract a Shadow Account profile from a user's trade journal."""

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Pass an actual integer or an integer-valued string like "3" or 3
  2. If the value is a float, round/parse it first (e.g. int(float(value))) if truncation is acceptable
  3. For optional fields, pass None or omit the kwarg entirely to get the default

Example fix

# before
tool.execute(lookback="1.5")
# after
tool.execute(lookback=1)  # or "1"
Defensive patterns

Strategy: type-guard

Validate before calling

def to_int(value, field, default=None):
    if value is None or value == "":
        return default
    try:
        return int(value)
    except (TypeError, ValueError, OverflowError):
        raise ValueError(f"{field} must be an integer, got {value!r}") from None

Type guard

def is_int_like(v) -> bool:
    if isinstance(v, bool) or v is None:
        return False
    try:
        int(v)
        return True
    except (TypeError, ValueError, OverflowError):
        return False

Try / catch

wrap the execute call in try/except ValueError and re-prompt/report the bad field

Prevention

When it happens

Trigger: Passing a non-numeric string like "abc" for an int field, a float string like "1.5" (int("1.5") fails), a list/dict value, or a float NaN; e.g. execute(max_depth="1.5").

Common situations: LLM tool calls quote numbers as strings with decimal points; JSON payloads that arrive as floats or nested objects; locale-formatted numbers like "1,000".

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


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