{"record":{"id":"36a7d0f710db2459","repo":"HKUDS/Vibe-Trading","slug":"unknown-barrier-type-barrier-type-r-valid-types","errorCode":null,"errorMessage":"unknown barrier type {barrier_type!r}; valid types: {BARRIER_TYPES}","messagePattern":"unknown barrier type (.+?); valid types: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/options.py","lineNumber":116,"sourceCode":"    \"up and out\": \"up-and-out\",\n    \"uo\": \"up-and-out\",\n    \"uoc\": \"up-and-out\",\n    \"uop\": \"up-and-out\",\n    \"up-and-in\": \"up-and-in\",\n    \"up_and_in\": \"up-and-in\",\n    \"up and in\": \"up-and-in\",\n    \"ui\": \"up-and-in\",\n    \"uic\": \"up-and-in\",\n    \"uip\": \"up-and-in\",\n}\n\n\ndef normalise_barrier_type(barrier_type: str) -> str:\n    \"\"\"Fold a barrier-type string to one of :data:`BARRIER_TYPES`.\"\"\"\n    cleaned = barrier_type.strip().lower()\n    if cleaned in _BARRIER_ALIASES:\n        return _BARRIER_ALIASES[cleaned]\n    raise ValueError(\n        f\"unknown barrier type {barrier_type!r}; valid types: {BARRIER_TYPES}\"\n    )\n\n\ndef normalise_option_type(option_type: str) -> str:\n    \"\"\"Fold an option-type string to ``\"call\"`` or ``\"put\"``.\n\n    Public because callers that *store* an option type must fold it with the\n    same rule the pricing functions use. Anything that keeps the raw string and\n    later compares it with ``== \"call\"`` will price a leg typed ``\"Call\"`` as a\n    call here and settle it as a put there.\n\n    WHY THIS ACCEPTS ALIASES BUT STILL REFUSES THE UNKNOWN\n    -----------------------------------------------------\n    There are two different failure modes and they need opposite treatment.\n\n    A config saying ``\"C\"``, ``\"calls\"`` or ``\"认购\"`` is *unambiguous* -- there\n    is exactly one thing it can mean, and refusing it breaks a working setup for","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/options.py#L98-L134","documentation":"normalise_barrier_type folds the barrier_type string (case-insensitive, whitespace-trimmed) against a table of aliases mapping to the canonical types in BARRIER_TYPES ('down-and-out', 'down-and-in', 'up-and-out', 'up-and-in'). Anything not in the alias table raises this error listing the valid types, because guessing a barrier direction would misprice the option structurally.","triggerScenarios":"Calling barrier_option_price(..., barrier_type='knock-out') or 'dao', 'Down and Out' with wrong separators, or a typo like 'down-and-in '; any string not present in _BARRIER_ALIASES after lowercasing/stripping.","commonSituations":"Porting code from a library with different names (QuantLib uses 'DownOut', PyVOL uses 'UO'); user-supplied config with free-text barrier names; abbreviations like 'DO'/'UI' that are not in the alias map.","solutions":["Use one of the canonical BARRIER_TYPES strings, e.g. 'down-and-out'.","Print BARRIER_TYPES / inspect _BARRIER_ALIASES to see accepted spellings.","Normalise user input centrally (whitelist + map) before it reaches the pricer."],"exampleFix":"# before\nprice = barrier_option_price(S, K, T, r, sigma, H, barrier_type='knock-out')\n\n# after\nprice = barrier_option_price(S, K, T, r, sigma, H, barrier_type='down-and-out')","handlingStrategy":"type-guard","validationCode":"from quantlib.options import BARRIER_TYPES\ncleaned = barrier_type.strip().lower()\nassert cleaned in BARRIER_TYPES, f'barrier_type must be one of {BARRIER_TYPES}'","typeGuard":"def is_valid_barrier_type(s: str) -> bool:\n    return isinstance(s, str) and s.strip().lower() in {\n        'down-and-out', 'down-and-in', 'up-and-out', 'up-and-in'}","tryCatchPattern":"try:\n    px = barrier_option_price(S, K, T, r, sigma, H, barrier_type)\nexcept ValueError as e:\n    if 'unknown barrier type' in str(e):\n        raise ConfigError(f'barrier_type {barrier_type!r} not supported') from e\n    raise","preventionTips":["Use a Literal/Enum for barrier types in your own config layer.","Whitelist-map external codes to canonical strings at ingestion.","Keep a unit test enumerating BARRIER_TYPES."],"tags":["options","barrier-option","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"}