{"record":{"id":"0e122c03f981d052","repo":"TheAlgorithms/Python","slug":"there-s-an-empty-parameter","errorCode":null,"errorMessage":"There's an empty parameter","messagePattern":"There's an empty parameter","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"dynamic_programming/viterbi.py","lineNumber":245,"sourceCode":"    >>> _validate_not_empty([\"a\"], [\"b\"], {\"c\":0.5}, {}, {\"f\": {\"g\": 0.7}})\n    Traceback (most recent call last):\n            ...\n    ValueError: There's an empty parameter\n    >>> _validate_not_empty([\"a\"], [\"b\"], None, {\"d\": {\"e\": 0.6}}, {\"f\": {\"g\": 0.7}})\n    Traceback (most recent call last):\n            ...\n    ValueError: There's an empty parameter\n    \"\"\"\n    if not all(\n        [\n            observations_space,\n            states_space,\n            initial_probabilities,\n            transition_probabilities,\n            emission_probabilities,\n        ]\n    ):\n        raise ValueError(\"There's an empty parameter\")\n\n\ndef _validate_lists(observations_space: Any, states_space: Any) -> None:\n    \"\"\"\n    >>> _validate_lists([\"a\"], [\"b\"])\n    >>> _validate_lists(1234, [\"b\"])\n    Traceback (most recent call last):\n            ...\n    ValueError: observations_space must be a list\n    >>> _validate_lists([\"a\"], [3])\n    Traceback (most recent call last):\n            ...\n    ValueError: states_space must be a list of strings\n    \"\"\"\n    _validate_list(observations_space, \"observations_space\")\n    _validate_list(states_space, \"states_space\")\n\n","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/dynamic_programming/viterbi.py#L227-L263","documentation":"Raised by viterbi()'s non-empty validation when any of its five parameters — observations_space, states_space, initial_probabilities, transition_probabilities, emission_probabilities — is empty (falsy). The Viterbi decoder needs at least one state, one observation symbol, and complete probability tables to run, so an empty any of these makes decoding undefined.","triggerScenarios":"Calling viterbi(observation, [], initial_prob, transition_prob, emission_prob) with an empty states list; passing {} for transition_probabilities; passing '' or [] for observations_space. Note: truthiness is used, so an empty dict/list/tuple all trigger it.","commonSituations":"Loading HMM parameters from a JSON/YAML file where a section is missing and deserializes to {}; empty observation sequence after a filter step removes all events; initializing tables programmatically and forgetting to populate them.","solutions":["Check all five structures are non-empty before calling viterbi and log which one is empty.","Fix the parameter loading code to fail loudly when a config section (states, transitions, emissions) is absent.","If the observation sequence is legitimately empty, short-circuit in your caller instead of calling viterbi."],"exampleFix":"# before\nviterbi([], states, initial_p, trans_p, emit_p)  # ValueError\n\n# after\nif not observations:\n    result = []  # nothing to decode\nelse:\n    result = viterbi(observations, states, initial_p, trans_p, emit_p)","handlingStrategy":"validation","validationCode":"def valid_hmm_args(obs, states, init_p, trans_p, emit_p) -> bool:\n    return all([obs, states, init_p, trans_p, emit_p])","typeGuard":null,"tryCatchPattern":"try:\n    viterbi(obs, states, init_p, trans_p, emit_p)\nexcept ValueError as e:\n    if 'empty parameter' in str(e):\n        raise RuntimeError(f'HMM config incomplete: {e}') from e\n    raise","preventionTips":["Fail loudly when loading HMM config: require every section present.","Short-circuit empty observation sequences before decoding.","Log which of the five parameters is empty during development."],"tags":["dynamic-programming","hmm","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}