New to configuration?See the Setup Configuration Overview for the complete workflow:install extras → create
.env → choose providers → handle pruning.Supported Frameworks
Cognee supports two structured output approaches:- LiteLLM + Instructor — Provider-agnostic client with Pydantic coercion (default)
- BAML — DSL-based framework with type registry and guardrails
How It Works
Cognee uses a unified interface that abstracts the underlying framework:STRUCTURED_OUTPUT_FRAMEWORK environment variable determines which backend processes your requests, but the API remains identical.
Configuration
- LiteLLM + Instructor (Default)
- BAML
The default framework — no extra install needed. Uses LiteLLM and the Optionally, control how the model is prompted for structured output:
instructor library to coerce LLM responses into Pydantic models.Instructor Modes
WhenSTRUCTURED_OUTPUT_FRAMEWORK=instructor, the instructor mode controls how Cognee asks the model for structured output — for example via the model’s native JSON-schema response, a plain JSON object, or a tool/function call. The value of LLM_INSTRUCTOR_MODE is passed directly to the instructor library’s Mode, so it must be one of instructor’s supported mode strings.
LLM_INSTRUCTOR_MODE is empty by default. When it is unset, Cognee either applies a provider-specific mode or defers to the underlying Instructor/LiteLLM default, so in most cases you don’t need to set it at all:
LLM_PROVIDER | Behavior when LLM_INSTRUCTOR_MODE is unset |
|---|---|
openai, azure with gpt-5 models | json_schema_mode |
openai, azure with other models | use Instructor/LiteLLM default |
| AWS Bedrock | json_schema_mode |
ollama, gemini, custom (OpenAI-compatible), llama.cpp | json_mode |
anthropic | anthropic_tools |
mistral | mistral_tools |
json_schema_mode, json_mode, tool_call, and markdown_json_mode.
Important Notes
- Unified Interface: Your application code uses the same
acreate_structured_output()call regardless of framework - Provider Flexibility: Both frameworks support the same LLM providers
- Output Consistency: Both produce identical Pydantic-validated results
- Performance: Framework choice doesn’t significantly impact performance
Troubleshooting
`1 validation error for Response: content Input should be a valid string ... input_type=dict`
`1 validation error for Response: content Input should be a valid string ... input_type=dict`
This error appears during
recall() / search() with completion search types such as GRAPH_COMPLETION, GRAPH_SUMMARY_COMPLETION, GRAPH_COMPLETION_COT, and RAG_COMPLETION.Cause. These search types ask the LLM for a plain-text answer (the retriever uses response_model=str). When the configured instructor mode doesn’t match what your model/provider actually supports, the model wraps its answer in a JSON object instead of returning plain text. The instructor backend then can’t coerce that dict into the expected string field, so Pydantic raises Input should be a valid string ... input_type=dict. This is common with OpenAI-compatible, custom, and local (Ollama / LM Studio) endpoints.Fixes:- Align the instructor mode with your provider. OpenAI/Azure
gpt-4o/gpt-5models work with the defaultjson_schema_mode. Endpoints that don’t support JSON-schema responses usually need a different mode: - Switch to BAML if a small/local model keeps wrapping answers in JSON. BAML bypasses instructor’s coercion and is more forgiving of loose model output:
- Skip the LLM completion step to confirm retrieval works independently of model output formatting. Pass
only_context=Trueto return the retrieved context directly — see Search Basics. If retrieval succeeds withonly_context=True, the problem is the structured-output configuration above, not your graph.
LLM Providers
Configure LLM providers for text generation
Overview
Return to setup configuration overview
Custom Prompts
Learn about custom prompt configuration