Skip to content

Integrate LangChain for type-safe AI orchestration#1

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/explore-langchain-integration
Draft

Integrate LangChain for type-safe AI orchestration#1
Copilot wants to merge 5 commits intomainfrom
copilot/explore-langchain-integration

Conversation

Copy link

Copilot AI commented Feb 6, 2026

Replaces manual JSON parsing and ad-hoc prompt management with LangChain's structured output and composable chains. Adds Pydantic validation to eliminate runtime parsing errors.

Core Changes

Structured Output (src/ai_utils.py, src/models.py)

  • call_gemini_structured(): Returns validated Pydantic models instead of raw JSON
  • Pydantic schemas define and enforce all data structures (SiteData, Product, DesignSystem, etc.)
  • Automatic retry logic (max_retries=2) via ChatVertexAI

Prompt Templates (src/langchain_prompts.py)

  • Centralized PromptTemplate objects replace string formatting
  • Reusable chains: component_chain, page_chain, layout_chain, css_chain
  • Single source of truth for all AI interactions

Website Generator (src/website_generator.py)

  • Refactored to use composable chains
  • Progress tracking integrated into generation flow
  • Unified error handling across all generation steps

Before/After

# Before: Manual parsing, fragile
response = call_gemini(prompt)
cleaned = response.strip().removeprefix("```json")
data = json.loads(regex.match(cleaned))  # May fail

# After: Type-safe, validated
data: SiteData = call_gemini_structured(
    prompt=prompt,
    pydantic_model=SiteData
)

Testing

  • test_langchain.py: 5/5 tests passing
  • CodeQL: 0 vulnerabilities
  • Backward compatible: call_gemini() maintained

Dependencies

langchain
langchain-google-vertexai
langchain-core
pydantic

Future Enablement

LangChain integration enables straightforward addition of:

  • Memory for conversational iteration
  • Agents for multi-step reasoning
  • RAG for design pattern retrieval
  • Multi-model fallback strategies
Original prompt

how can langchain improve this project


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Investigate how Langchain can enhance project functionality Integrate LangChain for type-safe AI orchestration Feb 6, 2026
Copilot AI requested a review from Elementx07 February 6, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants