{ "kind": "open-flow-workflow", "version": 1, "name": "Grounded Article MiniCheck", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_4c5d060a6396eefc": { "name": "Reference facts and article batch", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "facts": { "type": "string", "minLength": 1 }, "text": { "type": "string", "minLength": 1 } }, "required": [ "facts", "text" ], "additionalProperties": false } }, "nullable": false, "handle": "documents" } ] }, "n_e6168e9cd2db2cfd": { "inputs": { "documents": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_4c5d060a6396eefc", "output": "documents" } ] } }, "name": "Split all articles into claims", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "facts": { "type": "string", "minLength": 1 }, "text": { "type": "string", "minLength": 1 } }, "required": [ "facts", "text" ], "additionalProperties": false } }, "nullable": false, "handle": "documents" } ], "outputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "facts": { "type": "string", "minLength": 1 }, "text": { "type": "string", "minLength": 1 } }, "required": [ "facts", "text" ], "additionalProperties": false } }, "nullable": false, "handle": "documents" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 } }, "required": [ "documentIndex", "claimIndex", "claim" ], "additionalProperties": false } }, "nullable": false, "handle": "claims" } ], "name": "Split all articles into claims", "moduleId": "n_519b8dfc680c8d97", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_ac85fec923ac0878": { "inputs": { "documents": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e6168e9cd2db2cfd", "output": "documents" } ] }, "claims": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e6168e9cd2db2cfd", "output": "claims" } ] }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ac85fec923ac0878", "output": "state" } ] }, "response": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0498eecfa46cfa4d", "output": "body" } ] } }, "name": "Collect grounded claim judgments", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "facts": { "type": "string", "minLength": 1 }, "text": { "type": "string", "minLength": 1 } }, "required": [ "facts", "text" ], "additionalProperties": false } }, "nullable": false, "handle": "documents" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 } }, "required": [ "documentIndex", "claimIndex", "claim" ], "additionalProperties": false } }, "nullable": false, "handle": "claims" }, { "jsonSchema": { "type": "object", "properties": { "index": { "type": "integer", "minimum": 0 }, "checks": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } } }, "required": [ "index", "checks" ], "additionalProperties": false }, "nullable": true, "handle": "previousState" }, { "jsonSchema": {}, "nullable": true, "handle": "response" } ], "outputs": [ { "jsonSchema": { "type": "object", "properties": { "index": { "type": "integer", "minimum": 0 }, "checks": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } } }, "required": [ "index", "checks" ], "additionalProperties": false }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "object" }, "nullable": false, "handle": "body" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } }, "nullable": false, "handle": "unsupported" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "summaryInput" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "hasUnsupported" }, { "jsonSchema": { "type": "integer", "minimum": 0 }, "nullable": false, "handle": "count" } ], "name": "Collect grounded claim judgments", "moduleId": "n_7dac953b5eb36fd0", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_1a31560d2db58271": { "inputs": {}, "name": "More claims to check", "kind": "condition", "matchMode": "first", "cases": [ { "output": "more", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_ac85fec923ac0878", "output": "more" } }, "operator": "==", "right": { "kind": "value", "value": true } } ] } ] } ] }, "n_0498eecfa46cfa4d": { "inputs": { "url": { "kind": "value", "value": "https://ollama.example.com/api/chat" }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ac85fec923ac0878", "output": "body" } ] }, "auth.token": { "kind": "unset" } }, "name": "Check with Bespoke-MiniCheck", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Check with Bespoke-MiniCheck", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_8c13d8fffb2ca179": { "inputs": {}, "name": "Unsupported claims found", "kind": "condition", "matchMode": "first", "cases": [ { "output": "summarize", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_ac85fec923ac0878", "output": "hasUnsupported" } }, "operator": "==", "right": { "kind": "value", "value": true } } ] } ] } ] }, "n_0f3dc9edb3ec1171": { "inputs": { "summaryInput": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ac85fec923ac0878", "output": "summaryInput" } ] } }, "name": "Summarize unsupported claims", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "summaryInput" } ], "outputs": [ { "description": "The final result produced by the Agent.", "jsonSchema": { "type": "string" }, "nullable": false, "handle": "output" } ], "name": "Summarize unsupported claims", "executor": { "kind": "agent", "code": false, "model": "YOUR_SUPPORTED_SUMMARY_MODEL_ID", "prompt": "You are a fact-checking assistant. Your task is to analyze a list of statements, each accompanied by a \"yes\" or \"no\" indicating whether the statement is correct. Follow these guidelines:\n\n1. Review Process:\n a) Carefully read through each statement and its corresponding yes/no answer.\n b) Identify which statements are marked as incorrect (no).\n c) Ignore chit-chat sentences or statements that don't contain factual information.\n d) Count the total number of incorrect factual statements.\n\n2. Statement Classification:\n - Factual Statements: Contains specific information, data, or claims that can be verified.\n - Chit-chat/Non-factual: General comments, introductions, or transitions that don't present verifiable facts.\n\n3. Summary Structure:\n a) Overview: Provide a brief summary of the number of factual errors found.\n b) List of Problems: Enumerate the incorrect factual statements.\n c) Final Assessment: Offer a concise evaluation of the overall state of the article's factual accuracy.\n\n4. Prioritization:\n - Focus only on the factual statements marked as incorrect (no).\n - Ignore statements marked as correct (yes) and non-factual chit-chat.\n\n5. Feedback Tone:\n - Maintain a neutral and objective tone.\n - Present the information factually without additional commentary.\n\n6. Output Format:\n Present your summary in the following structure:\n\n ## Problem Summary\n [Number] incorrect factual statements were identified in the article.\n\n ## List of Incorrect Factual Statements\n 1. [First incorrect factual statement]\n 2. [Second incorrect factual statement]\n 3. [Third incorrect factual statement]\n (Continue listing all incorrect factual statements)\n\n ## Final Assessment\n Based on the number of incorrect factual statements:\n - If 0-1 errors: The article appears to be highly accurate and may only need minor factual adjustments.\n - If 2-3 errors: The article requires some revision to address these factual inaccuracies.\n - If 4 or more errors: The article needs significant revision to improve its factual accuracy.\n\nRemember, your role is to provide a clear, concise summary of the incorrect factual statements to help the writing team quickly understand what needs to be addressed. Ignore any chit-chat or non-factual statements in your analysis and summary.\n\n{{summaryInput}}", "maxRounds": 1, "tools": [] } } }, "n_6052780af6ef6a15": { "inputs": { "checks": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ac85fec923ac0878", "output": "state", "field": "checks" } ] }, "unsupported": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ac85fec923ac0878", "output": "unsupported" } ] }, "completion": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0f3dc9edb3ec1171", "output": "output" } ] } }, "name": "Complete editorial review report", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } }, "nullable": false, "handle": "checks" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } }, "nullable": false, "handle": "unsupported" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "completion" } ], "outputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } }, "nullable": false, "handle": "checks" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } }, "nullable": false, "handle": "unsupported" }, { "jsonSchema": { "type": "integer", "minimum": 0 }, "nullable": false, "handle": "count" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "summary" } ], "name": "Complete editorial review report", "moduleId": "n_57498924d3008595", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_7002b2f81adb66eb": { "name": "Grounded claim report", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } }, "nullable": false, "handle": "checks" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "documentIndex": { "type": "integer", "minimum": 0 }, "claimIndex": { "type": "integer", "minimum": 0 }, "claim": { "type": "string", "minLength": 1 }, "verdict": { "type": "string", "enum": [ "Yes", "No" ] } }, "required": [ "documentIndex", "claimIndex", "claim", "verdict" ], "additionalProperties": false } }, "nullable": false, "handle": "unsupported" }, { "jsonSchema": { "type": "integer", "minimum": 0 }, "nullable": false, "handle": "count" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "summary" } ], "outputMappings": { "checks": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_6052780af6ef6a15", "output": "checks" } ] }, "unsupported": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_6052780af6ef6a15", "output": "unsupported" } ] }, "count": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_6052780af6ef6a15", "output": "count" } ] }, "summary": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_6052780af6ef6a15", "output": "summary" } ] } } } }, "edges": [ { "source": "n_4c5d060a6396eefc", "target": "n_e6168e9cd2db2cfd" }, { "source": "n_e6168e9cd2db2cfd", "target": "n_ac85fec923ac0878" }, { "source": "n_ac85fec923ac0878", "target": "n_1a31560d2db58271" }, { "source": "n_1a31560d2db58271", "target": "n_0498eecfa46cfa4d", "sourceHandle": "more" }, { "source": "n_0498eecfa46cfa4d", "target": "n_ac85fec923ac0878" }, { "source": "n_1a31560d2db58271", "target": "n_8c13d8fffb2ca179", "sourceHandle": "otherwise" }, { "source": "n_8c13d8fffb2ca179", "target": "n_0f3dc9edb3ec1171", "sourceHandle": "summarize" }, { "source": "n_0f3dc9edb3ec1171", "target": "n_6052780af6ef6a15" }, { "source": "n_8c13d8fffb2ca179", "target": "n_6052780af6ef6a15", "sourceHandle": "otherwise" }, { "source": "n_6052780af6ef6a15", "target": "n_7002b2f81adb66eb" } ] } }, "modules": { "n_519b8dfc680c8d97": { "name": "Split all articles into claims", "imports": [], "source": "export function splitGroundedClaims(text) {\n if(typeof text!=='string'||!text.trim())throw new Error('Article text is empty.');\n const dates=[...text.matchAll(/\\b\\d{1,2}\\.\\s*(?:(?:Januar|Februar|März|April|Mai|Juni|Juli|August|September|Oktober|November|Dezember)|\\d{1,2}\\.)\\s*\\d{2,4}\\b/gi)].map(match=>[match.index,match.index+match[0].length]);\n const lists=[...text.matchAll(/^\\s*\\d+\\.\\s+/gm)].map(match=>[match.index,match.index+match[0].length]);\n const protectedRanges=[...dates,...lists].sort((a,b)=>a[0]-b[0]);\n let protectedIndex=0;\n const boundaries=[...text.matchAll(/(?<=[.!?])\\s+(?=[A-ZÄÖÜ]|$)/g)].filter(match=>{\n while(protectedIndex=range[1];\n });\n const claims=[];let offset=0;for(const boundary of boundaries){const claim=text.slice(offset,boundary.index).trim();if(claim)claims.push(claim);offset=boundary.index+boundary[0].length;}const last=text.slice(offset).trim();if(last)claims.push(last);return claims;\n}\nexport default function prepareGroundedClaims({documents}){\n if(!Array.isArray(documents))throw new Error('Provide an array of facts/text document pairs.');\n const claims=[];\n for(const [documentIndex,document] of documents.entries()){\n if(!document||typeof document.facts!=='string'||!document.facts.trim())throw new Error('Reference facts are empty.');\n for(const [claimIndex,claim] of splitGroundedClaims(document.text).entries())claims.push({documentIndex,claimIndex,claim});\n }\n return {documents,claims};\n}\n" }, "n_7dac953b5eb36fd0": { "name": "Collect grounded claim judgments", "imports": [], "source": "export function validateMiniCheckText(content){if(typeof content!=='string')throw new Error('Bespoke-MiniCheck answer is not text.');const verdict=content.trim();if(verdict!=='Yes'&&verdict!=='No')throw new Error('Bespoke-MiniCheck must answer Yes or No.');return verdict;}\nexport function readMiniCheckVerdict(response){\n if(!response||typeof response!=='object'||response.done!==true||response.model!=='bespoke-minicheck:latest'||response.message?.role!=='assistant'||typeof response.message.content!=='string')throw new Error('Ollama did not return a complete bespoke-minicheck answer.');\n return validateMiniCheckText(response.message.content);\n}\nexport default function collectGroundedChecks({documents,claims,previousState,response}){\n let state;\n if(previousState===null)state={index:0,checks:[]};\n else{\n const {index,checks}=previousState;\n if(!Number.isSafeInteger(index)||index<0||index>=claims.length||checks.length!==index)throw new Error('Invalid grounded-check frame.');\n state={index:index+1,checks:[...checks,{...claims[index],verdict:readMiniCheckVerdict(response)}]};\n }\n const next=claims[state.index],unsupported=state.checks.filter(check=>check.verdict==='No');\n return {state,body:{model:'bespoke-minicheck:latest',stream:false,messages:[{role:'user',content:next?'Document: '+documents[next.documentIndex].facts+'\\nClaim: '+next.claim:'unused-completed-frame'}]},more:state.index0,count:unsupported.length};\n}\n" }, "n_57498924d3008595": { "name": "Complete editorial review report", "imports": [], "source": "export default function finishGroundedReport({checks,unsupported,completion}){\n if(!Array.isArray(checks)||!Array.isArray(unsupported))throw new Error('Grounded check results are missing.');\n const summary=unsupported.length===0?'No unsupported claims were identified by the configured checker.':completion;\n if(typeof summary!=='string'||!summary.trim())throw new Error('The grounded-check summary is empty.');\n return {checks,unsupported,count:unsupported.length,summary:summary.trim()};\n}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }