{"record":{"id":"529aaeb6683b4fa8","repo":"chenfei-wu/TaskMatrix","slug":"format-error-please-try-again","errorCode":null,"errorMessage":"Format error, please try again.","messagePattern":"Format error, please try again\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"LowCodeLLM/src/planningLLM.py","lineNumber":105,"sourceCode":"                step_id = step[: left_indices[0]-2]\r\n                step_name = step[left_indices[0]+1: right_indices[0]]\r\n                step_description = step[left_indices[1]+1: right_indices[1]]\r\n                jump_str = step[left_indices[2]+1: right_indices[-1]]\r\n                if re.findall(re.compile(r'[A-Za-z]',re.S), jump_str) == []:\r\n                    workflow.append({\"stepId\": step_id, \"stepName\": step_name, \"stepDescription\": step_description, \"jumpLogic\": [], \"extension\": []})\r\n                    continue\r\n                jump_logic = []\r\n                left_indices = [_.start() for _ in re.finditer('\\[', jump_str)]\r\n                right_indices = [_.start() for _ in re.finditer('\\]', jump_str)]\r\n                i = 1\r\n                while i < len(left_indices):\r\n                    jump = {\"Condition\": jump_str[left_indices[i]+1: right_indices[i-1]], \"Target\": re.search(r'STEP\\s\\d', jump_str[left_indices[i+1]+1: right_indices[i]]).group(0)}\r\n                    jump_logic.append(jump)\r\n                    i += 3\r\n                workflow.append({\"stepId\": step_id, \"stepName\": step_name, \"stepDescription\": step_description, \"jumpLogic\": jump_logic, \"extension\": []})\r\n            return json.dumps(workflow)\r\n        except:\r\n            print(\"Format error, please try again.\")","sourceCodeStart":87,"sourceCodeEnd":105,"githubUrl":"https://github.com/chenfei-wu/TaskMatrix/blob/4b7664f8d3a23804ac1b795d75a73efd162769f0/LowCodeLLM/src/planningLLM.py#L87-L105","documentation":"Printed by planningLLM._txt2json when parsing the LLM's SOP text fails. The bare except catches any deviation from the expected 'STEP n: [name][description][[condition][Jump to STEP m]]' format — including AttributeError from re.search returning None, index errors from unbalanced brackets, or the model adding prose around the steps — and the function silently returns None.","triggerScenarios":"The LLM reply deviates from the strict STEP format: missing 'STEP' prefix, unbalanced [ ] brackets so left/right index lists misalign, jump text without a 'STEP n' target (re.search returns None -> .group(0) raises AttributeError), or extra commentary lines that pass the STEP filter but have fewer than 3 bracket groups.","commonSituations":"Weaker models (gpt-3.5-turbo) ignore the format instructions occasionally; temperature too high increases deviation; user task prompts that induce the model to answer the task instead of producing an SOP. Downstream this becomes a None workflow returned to the Flask endpoint and surfaced as the 'internal errors' 500.","solutions":["Retry the get_workflow/extend_workflow call — the message itself says 'please try again' since output is nondeterministic.","Lower the temperature passed to planningLLM to make format adherence more reliable.","Make _txt2json robust: skip non-conforming lines, guard re.search result before .group(0), and re-raise/log the exception instead of a bare print.","Strengthen the prompt suffix or validate the LLM output with a schema and re-prompt on failure."],"exampleFix":"# before\njump = {\"Condition\": ..., \"Target\": re.search(r'STEP\\s\\d', s).group(0)}\nexcept:\n    print(\"Format error, please try again.\")\n# after\nm = re.search(r'STEP\\s\\d+', s)\nif m is None:\n    continue\njump = {\"Condition\": ..., \"Target\": m.group(0)}\nexcept (IndexError, AttributeError) as e:\n    logging.exception('SOP parse failed: %s', e)\nraise  # or return error sentinel the caller can retry on","handlingStrategy":"retry","validationCode":"def looks_like_sop(text: str) -> bool:\n    lines = [l for l in text.split('\\n') if l.strip()]\n    return bool(lines) and sum(l.startswith('STEP') for l in lines) >= 1","typeGuard":null,"tryCatchPattern":"wf = llm.get_workflow(task)\nif wf is None or wf == 'OpenAI API error.':\n    wf = llm.get_workflow(task)  # format failures are stochastic; retry once","preventionTips":["Lower planning LLM temperature for format stability","Treat None/_txt2json failures as retryable","Guard re.search results before .group(0) if you patch _txt2json"],"tags":["llm-output-parsing","regex","format-validation","lowcodellm"],"backgroundTag":"llm-output-format-validation","analyzedSha":"4b7664f8d3a23804ac1b795d75a73efd162769f0","analyzedAt":"2026-08-27T13:26:11.787Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}