UN-2980 [FIX] Handle null response#1910
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| Filename | Overview |
|---|---|
| workers/executor/executors/answer_prompt.py | Guard in handle_json correctly widened from isinstance(str) to not isinstance(dict, list), preventing None/scalar values from silently bypassing the error branch. |
| prompt-service/src/unstract/prompt_service/services/answer_prompt.py | Parallel handle_json implementation still carries the old isinstance(parsed_data, str) guard — same null-response bug as fixed in the executor remains here. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[LLM returns answer] --> B{answer == 'na'?}
B -- Yes --> C[store None and return]
B -- No --> D[repair_json_with_best_structure]
D --> E{Result type?}
E -- "None / scalar / str" --> F["FIXED in executor: not isinstance dict or list"]
F --> G[log error, store empty dict, return]
E -- "dict or list" --> H[webhook / highlight processing]
H --> I[store result in structured_output]
E -- "None / scalar / str" --> J["STILL BROKEN in prompt-service: isinstance str check misses None"]
J --> K[silently stores None in structured_output]
Comments Outside Diff (1)
-
prompt-service/src/unstract/prompt_service/services/answer_prompt.py, line 400 (link)Same null-response bug unfixed in prompt-service
The prompt-service's
handle_jsonstill uses the oldisinstance(parsed_data, str)guard. When the LLM returnsnull,repair_json_with_best_structure(in the prompt-service version) callsrepair_json("null", return_objects=True)which returns PythonNone— not astr. The guard passes, theelsebranch runs, andNoneis silently stored instructured_output[prompt_key], breaking downstream consumers exactly as described in the PR.The fix is the same one-line change applied in the executor:
Prompt To Fix With AI
This is a comment left during a code review. Path: prompt-service/src/unstract/prompt_service/services/answer_prompt.py Line: 400 Comment: **Same null-response bug unfixed in prompt-service** The prompt-service's `handle_json` still uses the old `isinstance(parsed_data, str)` guard. When the LLM returns `null`, `repair_json_with_best_structure` (in the prompt-service version) calls `repair_json("null", return_objects=True)` which returns Python `None` — not a `str`. The guard passes, the `else` branch runs, and `None` is silently stored in `structured_output[prompt_key]`, breaking downstream consumers exactly as described in the PR. The fix is the same one-line change applied in the executor: How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: prompt-service/src/unstract/prompt_service/services/answer_prompt.py
Line: 400
Comment:
**Same null-response bug unfixed in prompt-service**
The prompt-service's `handle_json` still uses the old `isinstance(parsed_data, str)` guard. When the LLM returns `null`, `repair_json_with_best_structure` (in the prompt-service version) calls `repair_json("null", return_objects=True)` which returns Python `None` — not a `str`. The guard passes, the `else` branch runs, and `None` is silently stored in `structured_output[prompt_key]`, breaking downstream consumers exactly as described in the PR.
The fix is the same one-line change applied in the executor:
```suggestion
if not isinstance(parsed_data, (dict, list)):
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "Merge branch 'main' into UN-2980-bug-v-0..." | Re-trigger Greptile
chandrasekharan-zipstack
left a comment
There was a problem hiding this comment.
@Deepak-Kesavan I hope this code isn't duplicated elsewhere and required
…ng-issue-with-null-values
|
Test ResultsSummary
Runner Tests - Full Report
SDK1 Tests - Full Report
|



What
handle_jsonsilently storingNonewhen the LLM returns literalnullfor a JSON-type promptWhy
json, the application expects the stored result to be a dict or listnull,repair_json_with_best_structurecorrectly parsed it to PythonNone(JSON null → Python None)isinstance(parsed_data, str)only caught the case whererepair_jsoncompletely failed and returned the original string — it missedNoneentirelyNonewas silently written tostructured_output[prompt_key], with no error log or warn event, breaking downstream consumers that expected a dict/listHow
handle_jsonfromisinstance(parsed_data, str)tonot isinstance(parsed_data, (dict, list)){}as a safe fallback{"key": null}— still flow through unchanged"na"sentinel (storesNone) is untouchedrepair_json_with_best_structurehelper is not modified — the type constraint is specific to the JSON output type and belongs at the callerCan this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)
handle_jsonis only invoked forprompt_type == "json", where the contract is already "output must be a structured value". Any prior code path that received a scalar orNonefrom this function was already a latent contract violation. The"na"branch, therepair_json_with_best_structurehelper, and all other callers of that helper (e.g., structure tool) are untouched.Database Migrations
Env Config
Relevant Docs
Related Issues or PRs
Dependencies Versions
Notes on Testing
nullstructured_output[prompt_key] == None, no error/warn logstructured_output[prompt_key] == {}, error log + warn event published{"a": 1}still flows through unchanged{"key": null}is still stored as-is (not remapped to{})"na"responses still storeNoneas beforeScreenshots
Checklist
I have read and understood the Contribution Guidelines.