Skip to content

[ARCH] Reduce tight coupling in LLM pipeline to avoid PR conflicts #468

@Lochit-Vinay

Description

@Lochit-Vinay

🧩 Tight coupling in LLM pipeline is causing repeated merge conflicts

Summary

While working on a few improvements around the LLM pipeline (validation layer, fallback handling, prompt consistency), I kept running into the same issue — a lot of the core logic is tightly coupled across a few files:

  • src/llm.py
  • api/routes/forms.py
  • src/main.py

Because of this, even unrelated changes end up touching the same code paths, which leads to frequent merge conflicts.


What I’m noticing

Right now, multiple responsibilities are mixed together in the same flow:

  • prompt building
  • calling the LLM (Ollama)
  • parsing / cleaning responses
  • validation
  • fallback / error handling

Most of this lives inside or around LLM.main_loop().


Why this becomes a problem

  • Different PRs (validation, fallback, prompt tweaks, etc.) all modify the same logic
  • Conflicts keep reappearing even after resolving them once
  • It’s hard to work on one concern without affecting others
  • Slows down contribution and increases the chance of introducing bugs during merges

Example

While working on:

all of them end up overlapping in the same execution path, which makes rebasing messy.


Possible direction

Maybe we can move toward a slightly more modular flow like:

Input → Prompt Builder → LLM Client → Response Parser → Validator → Output

Not suggesting a big rewrite — even small separations could help, like:

  • isolating prompt building
  • separating the LLM call layer
  • keeping validation independent (pluggable)
  • reducing logic inside the main loop

Why this could help

  • Fewer merge conflicts across active PRs
  • Easier to work on features independently
  • Cleaner structure for future additions (confidence scoring, retries, async, etc.)
  • Better testability

Context

This came up while actively working on multiple PRs touching the same pipeline — I had to rebase multiple times due to overlapping changes.


Proposed approach

Rather than a large refactor, this could be tackled incrementally with small, focused PRs (e.g., extracting the LLM client, isolating prompt building, introducing validation as a separate step).

Happy to start with a small initial PR and iterate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode refactoring, cleaning

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions