Add safety preprocessing and routing to ReactToMe#99
Conversation
heliamoh
commented
Nov 10, 2025
- Add a reusable preprocessing graph that rephrases the user query, runs the safety checker, and carries forward structured results.
- Refine the safety checker prompt to return explicit safety and reason_unsafe fields.
- Update BaseGraphBuilder and ReactToMeGraphBuilder to gate RAG vs. refusal based on safety, with a new unsafe-answer generator.
| return BaseState( | ||
| additional_content=AdditionalContent(search_results=search_results) | ||
| **state, | ||
| additional_content=AdditionalContent(search_results=search_results), |
There was a problem hiding this comment.
Does adding **state in spots like this solve some issue with updating the state?
There was a problem hiding this comment.
The BaseState(**state, …) merge isn’t there to work around a bug—it’s there because LangGraph hands us an evolving state dict, and we don’t want to drop any of the fields that preprocessing or earlier nodes already wrote (rephrased input, safety tag, chat history, etc.). Postprocess only needs to add additional_content, so merging **state with the new field preserves the existing state while layering on the search results. If we just returned BaseState(additional_content=...), we’d lose everything else that was already in the state and downstream nodes would break.
There was a problem hiding this comment.
LangGraph implicitly updates the state using the returned dict without dropping omitted fields, so we shouldn't need to do this.
b7fb7ee to
855ad4d
Compare
|
moving to #100 |