Skip to main content
Debugging AI applications requires specialized tools to understand model behavior, trace execution flows, and diagnose issues. Genkit provides comprehensive debugging capabilities through traces, the Developer UI, and CLI tools.

Trace-Based Debugging

Genkit automatically collects detailed execution traces that show every step of your flow execution.

Enabling Traces

Traces are automatically collected when:
  1. Using genkit start:
  2. Running with GENKIT_ENV=dev:
  3. Executing flows via CLI:

Viewing Traces in Developer UI

The Developer UI provides the most powerful trace inspection:
  1. Start the Developer UI:
  2. Navigate to Traces section at http://localhost:4000
  3. Select a trace to inspect:
    • Recent executions appear at the top
    • Failed executions are highlighted
    • Click any trace to view details

Trace Information

Each trace includes:
  • Span Tree: Hierarchical view of all operations
  • Timing Data: Duration of each step
  • Input/Output: Data passed between steps
  • Model Interactions: Prompts sent and responses received
  • Error Details: Stack traces and error messages
  • Metadata: Flow name, version, labels, and attributes
Example trace for a greeting flow:

Debugging Common Issues

Flow Execution Failures

Symptom: Flow throws an error or returns unexpected results Debug Steps:
  1. Check the trace in the Developer UI:
    • Identify which step failed
    • Review error message and stack trace
    • Examine input data to that step
  2. Run the flow with test data:
  3. Verify input schema:
  4. Check each step:
    • Review the trace to see where execution stopped
    • Check if null or undefined values are passed
    • Verify model responses are as expected

Model Response Issues

Symptom: Model returns unexpected or low-quality responses Debug Steps:
  1. Inspect the prompt in traces:
    • View the exact prompt sent to the model
    • Check if template variables were substituted correctly
    • Verify context and examples are included
  2. Test prompt directly in Developer UI:
    • Navigate to Prompts section
    • Select your prompt
    • Try different inputs
    • Compare outputs from different models
  3. Add prompt logging:
  4. Check model configuration:

Streaming Issues

Symptom: Streaming output doesn’t work or is incomplete Debug Steps:
  1. Test streaming with CLI:
  2. Verify streaming implementation:
  3. Check for blocking operations:
    • Ensure you’re not awaiting the full response before streaming
    • Verify no synchronous operations block the event loop

Performance Issues

Symptom: Flows are slow or timeout Debug Steps:
  1. Analyze timing in traces:
    • Open the trace in Developer UI
    • Identify the slowest spans
    • Check if model calls are taking too long
  2. Measure specific operations:
  3. Check for unnecessary operations:
    • Review trace to find redundant model calls
    • Look for sequential operations that could be parallel
    • Verify retrieval queries are optimized
  4. Optimize model configuration:

Context and RAG Issues

Symptom: Model doesn’t use provided context or retrieval fails Debug Steps:
  1. Verify context is passed:
  2. Inspect retrieval in traces:
  3. Check document retrieval:
    • View retriever span in trace
    • Verify documents were found
    • Check similarity scores
    • Ensure embeddings are generated correctly

Schema Validation Errors

Symptom: Input/output validation fails Debug Steps:
  1. Add detailed error handling:
  2. Test schema directly:
  3. Review trace for schema errors:
    • Check error message in trace
    • Verify actual vs expected types
    • Ensure all required fields are provided

Developer UI Debugging Features

Real-Time Trace Inspection

When running with genkit start, traces appear immediately:
  1. Run a flow from the Flows section
  2. Click “View Trace” to inspect execution
  3. Expand each span to see details
  4. Review timing to identify bottlenecks

Comparing Executions

Compare multiple executions to identify patterns:
  1. Run the same flow with different inputs
  2. View traces side-by-side
  3. Compare model responses
  4. Identify inconsistencies

Error Highlighting

Failed executions are clearly marked:
  • Red indicators for errors
  • Stack traces in span details
  • Error messages at the top level
  • Failed step highlighted in span tree

CLI Debugging Commands

Running Flows with Verbose Output

Extracting Debug Data

Extract traces for offline analysis:

Batch Testing for Debugging

Test multiple scenarios:
Then review all traces in the Developer UI filtered by label.

Logging Best Practices

Strategic Console Logs

Add logs at key points:

Structured Logging

Use JSON for structured logs:

Debugging in Production

While you shouldn’t run with GENKIT_ENV=dev in production, you can:
  1. Use evaluation datasets to reproduce issues:
  2. Test locally with production data:
  3. Enable production monitoring (see Observability docs)

Tips for Effective Debugging

  1. Always check traces first - They contain the most complete information
  2. Use labels to organize debug sessions
  3. Test incrementally - Debug one component at a time
  4. Compare working vs broken - Run working examples alongside failing ones
  5. Save traces - Extract and save traces for complex issues
  6. Use streaming - Helps identify where generation stops
  7. Review prompts - Ensure templates render correctly
  8. Check schemas - Validate input/output types match expectations

Common Debugging Patterns

Isolate the Issue

Binary Search Debugging

Comment out half the flow to find the problematic section:

Add Intermediate Outputs

Next Steps