🚀 Try it Live: https://ahteshamlatiflogicchatbot.vercel.app/
A web-based, deterministic AI engine designed to validate natural-language arguments using formal Rules of Inference, Rules of Replacement, and Categorical Logic.
Unlike general-purpose LLMs that are prone to hallucination when handling discrete mathematics, this system forces the AI into a strict, rule-bound state machine.
- Deterministic Output: The core reasoning engine (
arcee-ai/trinity-large-thinking) is clamped attemperature: 0to ensure reproducible mathematical proofs. - Defensive JSON Parsing: Implemented server-side regex boundary tracking (
/\{[\s\S]*\}/) to strictly extract and sanitize the JSON payload, preventing UI crashes from markdown leaks or conversational filler. - Edge-Case Resilience: Gracefully handles unstructured noise (typos, empty inputs) by yielding formal schema errors rather than wasting pipeline bandwidth.
Transforms plain-English arguments into symbolic representations and validates them against classical Rules of Inference & Replacement:
- Modus Ponens & Modus Tollens
- Hypothetical & Disjunctive Syllogism
- Addition, Simplification, & Conjunction
- De Morgan’s Laws, Double Negation, Commutation, & Distribution
Automatically extracts and analyzes complex categorical syllogisms to determine:
- Proposition types (A, E, I, O)
- Mood and Figure (e.g.,
AAA-1) - Exact logical fallacies (e.g.,
Illicit Major,Qualitative Balance)
Returns a strict JSON array containing the step-by-step mathematical proof, clearly citing the rules applied at each derivation step while explaining why invalid arguments fail.
{
"valid": true,
"type": "Propositional Logic",
"mood": null,
"details": null,
"proof": [
{ "step": 1, "statement": "R → W", "rule": "Premise" },
{ "step": 2, "statement": "R", "rule": "Premise" },
{ "step": 3, "statement": "W", "rule": "Modus Ponens" }
],
"error": null
}- Frontend: Vanilla HTML5, CSS3, JavaScript
- Backend: Node.js, Express.js
- AI Integration: OpenRouter API
- Deployment: Vercel
git clone https://github.com/Ahtesham-Latif/Logic_Chatbot.git
cd Logic_Chatbotnpm installCreate a .env file in the root directory:
cp .env.example .envAdd the following values inside .env:
OPENROUTER_API_KEY=your_openrouter_api_key_here
PORT=3030
NODE_ENV=developmentnpm startThe application will be available at:
http://localhost:3030
This project was created to help students understand and practice formal logical reasoning.
It is useful for:
- Philosophy and logic students
- Debate preparation
- Critical thinking exercises
- Demonstrations of AI-assisted reasoning systems
The chatbot is intentionally designed to follow strict formal logic rules while avoiding informal or probabilistic reasoning patterns.
- GitHub: https://github.com/Ahtesham-Latif
- LinkedIn: https://www.linkedin.com/in/ahtesham-latif
This project is licensed for educational and academic use.