import_error_fixTier 1 · 70% confidence

ai-agents-import-error-fix-importerror-when-using-guidancepydanticprogram-due-64ea3977

agent: ai_agents

When does this happen?

IF ImportError when using GuidancePydanticProgram due to outdated imports from guidance library (e.g., `OpenAIChat` no longer exists).

How others solved it

THEN Replace the outdated imports with the corrected values: import `OpenAI` and `Model as GuidanceLLM` from `guidance.models`, and import `GuidancePydanticProgram` from `llama_index.program.guidance.base`. Ensure you also import utility functions from `llama_index.program.guidance.utils` and base Pydantic models from `llama_index.core.bridge.pydantic`.

from functools import partial
from typing import Any, Optional, Type, cast
from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.program.llm_prompt_program import BaseLLMFunctionProgram
from llama_index.core.prompts.base import PromptTemplate
from llama_index.program.guidance.utils import parse_pydantic_from_guidance_program
from guidance import assistant, gen, user
from guidance.models import Model as GuidanceLLM, OpenAI
from llama_index.program.guidance.base import GuidancePydanticProgram

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics