{"record":{"id":"19241027088cdeed","repo":"HKUDS/Vibe-Trading","slug":"unrecognised-option-type-option-type-r-accepted","errorCode":null,"errorMessage":"unrecognised option_type {option_type!r}. Accepted (any case): {sorted(_CALL_ALIASES)} for a call, {sorted(_PUT_ALIASES)} for a put. An unrecognised type is not defaulted, because defaulting one is how a call leg gets settled as a put.","messagePattern":"unrecognised option_type (.+?)\\. Accepted \\(any case\\): (.+?) for a call, (.+?) for a put\\. An unrecognised type is not defaulted, because defaulting one is how a call leg gets settled as a put\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/options.py","lineNumber":159,"sourceCode":"    happened, so an unknown string still raises.\n\n    Args:\n        option_type: Caller-supplied option type. Case, surrounding whitespace\n            and the aliases above are all accepted.\n\n    Returns:\n        Either ``\"call\"`` or ``\"put\"``.\n\n    Raises:\n        ValueError: If the string matches no known spelling. The message lists\n            what is accepted, so the fix does not need a source read.\n    \"\"\"\n    folded = str(option_type).strip().lower()\n    if folded in _CALL_ALIASES:\n        return _CALL\n    if folded in _PUT_ALIASES:\n        return _PUT\n    raise ValueError(\n        f\"unrecognised option_type {option_type!r}. Accepted (any case): \"\n        f\"{sorted(_CALL_ALIASES)} for a call, {sorted(_PUT_ALIASES)} for a put. \"\n        \"An unrecognised type is not defaulted, because defaulting one is how a \"\n        \"call leg gets settled as a put.\"\n    )\n\n\ndef _intrinsic(S: float, K: float, option_type: str) -> float:\n    \"\"\"Undiscounted exercise value of an option.\n\n    Args:\n        S: Underlying spot price.\n        K: Strike price.\n        option_type: Normalised ``\"call\"`` or ``\"put\"``.\n\n    Returns:\n        ``max(S - K, 0)`` for a call, ``max(K - S, 0)`` for a put. Always a\n        float, even for integer inputs, so the public annotations hold.","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/options.py#L141-L177","documentation":"normalise_option_type accepts case-insensitive call/put aliases and refuses everything else with an explicit error. The long message is deliberate: defaulting an unrecognised type to 'call' is exactly how a put leg in a structured product gets priced and settled as a call, so the library forces the caller to fix the input.","triggerScenarios":"Calling bs_price/implied_volatility/barrier_option_price with option_type='c', 'CALL', or a valid alias works, but values like 'callspread', 'both', '', None stringified as 'None', or non-English terms raise this.","commonSituations":"Config files with option_type: C/P abbreviations not in the alias table; loops over legs where one leg has a typo or an empty string; deserialised JSON where option_type is null and gets coerced to the string 'None'.","solutions":["Fix the value to a recognised call/put alias (e.g. 'call' or 'put').","Map upstream codes explicitly before calling: {'C': 'call', 'P': 'put'}.","Add schema validation on incoming trade payloads so a bad type fails at ingestion with full context."],"exampleFix":"# before\nprice = bs_price(S, K, T, r, sigma, option_type=leg['type'])  # leg['type'] == 'C'\n\n# after\nCANON = {'C': 'call', 'P': 'put', 'CALL': 'call', 'PUT': 'put'}\nprice = bs_price(S, K, T, r, sigma, option_type=CANON[leg['type'].upper()])","handlingStrategy":"type-guard","validationCode":"CANON = {'c': 'call', 'call': 'call', 'p': 'put', 'put': 'put'}\nopt = CANON.get(str(option_type).strip().lower())\nassert opt in ('call', 'put'), f'bad option_type {option_type!r}'","typeGuard":"def is_valid_option_type(s) -> bool:\n    return isinstance(s, str) and str(s).strip().lower() in ('c', 'call', 'p', 'put')","tryCatchPattern":"try:\n    px = bs_price(S, K, T, r, sigma, option_type)\nexcept ValueError as e:\n    if 'unrecognised option_type' in str(e):\n        raise TradeValidationError(option_type) from e\n    raise","preventionTips":["Model option_type as a Literal['call','put'] enum in trade schemas.","Reject null/empty option_type at payload validation, never default it.","Map exchange codes (C/P) explicitly once, at the edge."],"tags":["options","option-type","input-validation","string-enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}