← ClaudeAtlas

code-and-llm-collaborationlisted

Design patterns for layering deterministic code and LLM calls in a single pipeline or agent. Use when designing a pipeline that mixes semantic and structural work — distillation, extraction with validation, approval gates, orchestrated multi-step workflows. Catalogs four load-bearing layering patterns (LLM→Code guard, Code filter→LLM, LLM judge + Code enforce, Code orchestrator + LLM worker) with when-to-use, failure modes, and minimal code sketches. Macro-level companion to the micro "which tool for this one task" question.
shimo4228/code-and-llm-collaboration · ★ 1 · AI & Automation · score 78
Install: claude install-skill shimo4228/code-and-llm-collaboration
# Code and LLM Collaboration When building a pipeline that mixes semantic work (summarization, classification, extraction) with structural work (validation, filtering, dispatch), the interesting question is **not** "which one should I use?" It is **"in what order, and with what contract between the layers?"** Code and LLMs work best as layers, each doing the job the other cannot: - Code is deterministic, cheap, and auditable but cannot understand meaning. - LLMs handle meaning but are slow, probabilistic, and attackable. Four layering patterns cover most real pipelines. Each has a characteristic failure mode when layers are skipped or reversed. Recognize which pattern you need, wire it in the correct order, and keep the contract between layers strict. --- ## Pattern 1 — LLM → Code guard **Shape.** The LLM produces structured output. A code layer validates that output against a schema and enforces constraints before anything downstream consumes it. If validation fails, the pipeline rejects or retries — it does not pass partial output forward. **When to use.** - Any time LLM output will be written to a persistent store (database, knowledge file, identity document) - Any time LLM output will be executed as structured data (tool-call arguments, JSON config, API payload) - Any time the LLM is allowed to propose changes that a human will review — the guard prevents a human from rubber-stamping an invalid proposal **Key insight.** The LLM is allowed to be wrong. The guard