{"record":{"id":"3215ba41f652b969","repo":"HKUDS/Vibe-Trading","slug":"field-name-cannot-be-empty","errorCode":null,"errorMessage":"{field_name} cannot be empty","messagePattern":"(.+?) cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/goal/policy.py","lineNumber":32,"sourceCode":")\n\n\ndef normalize_required_text(value: str, field_name: str) -> str:\n    \"\"\"Strip and validate a required text field.\n\n    Args:\n        value: User supplied text.\n        field_name: Field name for the error message.\n\n    Returns:\n        The stripped value.\n\n    Raises:\n        ValueError: If the stripped value is empty.\n    \"\"\"\n    text = value.strip()\n    if not text:\n        raise ValueError(f\"{field_name} cannot be empty\")\n    return text\n\n\ndef reject_live_execution_objective(objective: str) -> None:\n    \"\"\"Reject direct live-trading or order-execution goal text.\n\n    Args:\n        objective: Research goal objective.\n\n    Raises:\n        ValueError: If the objective looks like an execution request.\n    \"\"\"\n    text = objective.strip()\n    for pattern in _EXECUTION_PATTERNS:\n        if pattern.search(text):\n            raise ValueError(\"live trading or execution goals are not supported\")\n","sourceCodeStart":14,"sourceCodeEnd":49,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/goal/policy.py#L14-L49","documentation":"normalize_required_text in agent/src/goal/policy.py strips whitespace from a required text field and raises ValueError('{field_name} cannot be empty') when nothing remains. It is the shared sanitizer behind goal/session APIs like replace_goal, update_goal, get_goal, list_criteria and list_claims, so blank or whitespace-only inputs fail fast.","triggerScenarios":"Calling any goal API with session_id='  ', objective='', or a criteria/claim text of '' (or '\\t'/'\\n') — the strip() result is empty and the guard fires.","commonSituations":"CLI/agent passing an unfiltered user prompt as the goal objective; frontend sending empty strings instead of omitting fields; trailing-newline strings from templates or config; tests that construct goals from blank fixtures.","solutions":["Pass a non-blank, trimmed string (objective, session_id, criterion text) to the goal API","Validate in the caller/UI before invoking the store: reject empty input with a user-facing message","If the value comes from a template, strip it yourself and provide a sensible default","Check you are not accidentally passing the wrong positional arg (e.g. session_id where objective goes)"],"exampleFix":"# before\nstore.replace_goal(session_id=\"s1\", objective=\"   \", criteria=[\"x\"])\n# after\nobjective = \"Identify momentum factors in US equities\".strip()\nstore.replace_goal(session_id=\"s1\", objective=objective, criteria=[\"x\"])","handlingStrategy":"validation","validationCode":"def require_text(value: str, field: str) -> str:\n    cleaned = (value or '').strip()\n    if not cleaned:\n        raise ValueError(f'{field} must be non-blank')\n    return cleaned\n\nobjective = require_text(user_input, 'goal objective')\nsession_id = require_text(session_id, 'session_id')\nstore.replace_goal(session_id=session_id, objective=objective, criteria=[...])","typeGuard":"def is_non_blank(value: str) -> bool:\n    return isinstance(value, str) and bool(value.strip())","tryCatchPattern":"try:\n    store.replace_goal(session_id=sid, objective=obj, criteria=cs)\nexcept ValueError as e:\n    if 'cannot be empty' in str(e):\n        # surface a user-facing 'required field' message\n        raise UserInputError(str(e)) from e\n    raise","preventionTips":["Strip and check text inputs at the UI/agent boundary before calling goal APIs","Reject empty strings early with a field-specific message","Watch for whitespace-only strings from templates and file reads"],"tags":["validation","goal-store","empty-string","python"],"backgroundTag":"required-field-empty","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}