# graph_data_analysis.py — Data Analysis (LangGraph sketch) # pip install langgraph langchain-core (pin yourself) # Use a local chat model binder; do not embed secrets. from typing import TypedDict, Literal from langgraph.graph import StateGraph, END SYSTEM = """You are a data analysis desk. Goal: findings from pasted numbers only. RULES: - Always emit ALL four OUTPUT sections. - Never invent row values, dates, weekdays, or metrics not in the paste. - Quote the exact cell values you use in each Key finding. - Note blank/missing cells explicitly; do not fill blanks with guesses. - Do not invent averages; if you cannot compute carefully write "not computed — needs human calc". - Do not claim deploy/product events caused gold/market moves unless the paste states that link. - If paste says SAMPLE/synthetic, say so in Dataset snapshot. - Prefer max 5 accurate findings over 7 wrong ones. - Do not invent rows. If math is approximate, say so. - Call out sample size, missing fields, and selection bias. - No trading/investment advice. No auto-spend recommendations. - Charts described in text only unless user provides image. OUTPUT: 1) Dataset snapshot 2) Key findings (max 7) 3) Caveats 4) Next checks / cuts to request""" class State(TypedDict): user_input: str draft: str approved: bool notes: str def produce(state: State) -> State: # Pseudo: call your local model with SYSTEM + state["user_input"] draft = "[MODEL OUTPUT PLACEHOLDER — wire your local LLM here]\n" + state["user_input"][:500] return {**state, "draft": draft, "notes": "awaiting human"} def human_gate(state: State) -> State: # In real use: interrupt / input() / UI approval. # Default False so nothing auto-publishes. return {**state, "approved": False} def route_after_gate(state: State) -> Literal["done", "revise"]: return "done" if state.get("approved") else "done" # stage-1: always end after gate g = StateGraph(State) g.add_node("produce", produce) g.add_node("human_gate", human_gate) g.set_entry_point("produce") g.add_edge("produce", "human_gate") g.add_conditional_edges("human_gate", route_after_gate, {"done": END, "revise": "produce"}) app = g.compile() if __name__ == "__main__": out = app.invoke({"user_input": "PASTE_EXAMPLE_IN", "draft": "", "approved": False, "notes": ""}) print(out)