This document provides solutions for common issues that may arise when working with the Congress.gov API Chatbot application.
- Application Startup Issues
- API Connection Issues
- LLM Integration Issues
- Deployment Issues
- Performance Issues
- Common Error Messages
- Logging and Debugging
Symptoms:
- Error message:
Failed to load configuration - Application exits immediately after starting
Possible Causes and Solutions:
-
Missing Environment Variables
The application requires several environment variables to be set. Check if all required environment variables are set:
# Required environment variables CONGRESS_API_KEY=your_congress_api_key GENAI_API_KEY=your_GENAI_API_KEY GENAI_API_BASE_URL=your_GENAI_API_BASE_URL LLM=gpt-4o-miniSolution: Create a
.envfile in the project root with the required environment variables or set them directly in your environment. -
Invalid API Keys
The API keys provided may be invalid or expired.
Solution: Verify that your Congress.gov API key and GenAI API key are valid and active.
-
Port Already in Use
The default port (8080) may already be in use by another application.
Solution: Set a different port using the
PORTenvironment variable:PORT=8081 go run cmd/server/main.go
Symptoms:
- Error message:
Failed to create public directory - Application exits after starting
Possible Causes and Solutions:
-
Permissions Issue
The application may not have permission to create the public directory.
Solution: Check the permissions of the directory where the application is running and ensure the user running the application has write permissions.
-
Disk Space Issue
The disk may be full, preventing the creation of new files and directories.
Solution: Free up disk space or run the application in a location with sufficient disk space.
Symptoms:
- Error message:
API request failed with status code: 401 - Error message:
API request failed with status code: 403 - Error message:
API request failed with status code: 429
Possible Causes and Solutions:
-
Invalid API Key
The Congress.gov API key may be invalid or expired.
Solution: Verify that your Congress.gov API key is valid and active. You can get a new API key at https://api.congress.gov/sign-up/.
-
Rate Limiting
The Congress.gov API has rate limits that may be exceeded.
Solution: Implement exponential backoff and retry logic for API calls. The application already includes a caching mechanism to reduce the number of API calls.
-
Network Issues
The application may not be able to connect to the Congress.gov API due to network issues.
Solution: Check your network connection and ensure that the application can reach the Congress.gov API. You can test this with a simple curl command:
curl -H "X-API-Key: your_congress_api_key" https://api.congress.gov/v3/bill
Symptoms:
- Error message:
Failed to create LLM client - Error message:
Failed to generate response: context deadline exceeded
Possible Causes and Solutions:
-
Invalid API Key or URL
The GenAI API key or URL may be invalid or expired.
Solution: Verify that your GenAI API key and URL are valid and active.
-
Rate Limiting or Quota Exceeded
The GenAI LLM service may have rate limits or quotas that are exceeded.
Solution: Check your usage and quotas for the GenAI LLM service. Consider upgrading your plan if necessary.
-
Network Issues
The application may not be able to connect to the GenAI LLM service due to network issues.
Solution: Check your network connection and ensure that the application can reach the GenAI LLM service.
Symptoms:
- LLM responses are not relevant to the user's query
- LLM responses contain incorrect information
- LLM responses are too generic or vague
Possible Causes and Solutions:
-
Insufficient Context
The LLM may not have enough context to generate a relevant response.
Solution: Ensure that the system prompt provides sufficient context about the application's purpose and capabilities. You can modify the system prompt in the
Initializemethod ininternal/service/chatbot.go. -
Temperature Setting Too High
The temperature parameter controls the randomness of the LLM's responses. A higher temperature results in more creative but potentially less accurate responses.
Solution: Lower the temperature parameter in the LLM client. The application currently uses a temperature of 0.3, which is a good balance between creativity and accuracy.
-
Incorrect API Planning
The LLM may not correctly determine which Congress.gov API to call based on the user's query.
Solution: Improve the API planning prompt in the
ProcessUserQuerymethod ininternal/service/chatbot.goto provide more guidance to the LLM.
Symptoms:
- LLM responses take a long time to generate
- Application appears to hang when processing user queries
Possible Causes and Solutions:
-
Large Context Window
The conversation history may be too large, resulting in a large context window for the LLM.
Solution: Implement a mechanism to truncate the conversation history when it becomes too large. You can modify the
GetConversationHistorymethod ininternal/service/chatbot.goto limit the number of messages returned. -
Complex Queries
Some queries may require multiple API calls and complex processing.
Solution: Implement a timeout for LLM calls and provide feedback to the user when a query is taking a long time to process. The application already includes a timeout for LLM calls in the
HandleChatmethod ininternal/handler/handler.go. -
Network Latency
Network latency may contribute to slow LLM responses.
Solution: Consider deploying the application closer to the GenAI LLM service to reduce network latency.
Symptoms:
- Error message:
Failed to push application - Error message:
Failed to bind service - Error message:
Failed to start application
Possible Causes and Solutions:
-
Missing Environment Variables
The application requires several environment variables to be set.
Solution: Set the required environment variables using the
cf set-envcommand:cf set-env congress-chatbot CONGRESS_API_KEY your_congress_api_key
-
Service Binding Issues
The application may fail to bind to the GenAI LLM service.
Solution: Check if the service exists and is available:
cf services
If the service doesn't exist, create it:
cf create-service genai PLAN_NAME congress-llm
Then bind the service to the application:
cf bind-service congress-chatbot congress-llm
-
Memory or Disk Space Issues
The application may require more memory or disk space than allocated.
Solution: Increase the memory or disk space allocation in the
manifest.ymlfile:applications: - name: congress-chatbot memory: 512M disk_quota: 512M
Or use the
cf scalecommand:cf scale congress-chatbot -m 512M -k 512M
Symptoms:
- Application uses a lot of memory
- Application crashes with out-of-memory errors
Possible Causes and Solutions:
-
Large Conversation History
The conversation history may be stored in memory and grow too large.
Solution: Implement a mechanism to truncate the conversation history when it becomes too large. You can modify the
GetConversationHistorymethod ininternal/service/chatbot.goto limit the number of messages returned. -
Memory Leaks
The application may have memory leaks.
Solution: Use a memory profiler to identify and fix memory leaks. You can use the Go built-in memory profiler:
go tool pprof -http=:8081 http://localhost:8080/debug/pprof/heap
Note: You'll need to add the pprof middleware to the Fiber app in
cmd/server/main.go:import "github.com/gofiber/fiber/v2/middleware/pprof" // ... app.Use(pprof.New())
Symptoms:
- Application takes a long time to respond to user queries
- Application appears to hang when processing user queries
Possible Causes and Solutions:
-
Inefficient API Calls
The application may make too many API calls or inefficient API calls.
Solution: Implement caching for API responses to reduce the number of API calls. The application already includes a caching mechanism in the
CongressClientstruct inapi/congress_client.go. -
Inefficient LLM Usage
The application may use the LLM inefficiently.
Solution: Optimize the prompts and context provided to the LLM to reduce the amount of processing required. You can modify the system prompt in the
Initializemethod ininternal/service/chatbot.go. -
Insufficient Resources
The application may not have enough resources (CPU, memory) to handle the load.
Solution: Increase the resources allocated to the application or scale the application horizontally by adding more instances.
Cause: The application failed to load the configuration from environment variables or service bindings.
Solution: Check if all required environment variables are set and valid. See Application Startup Issues for more details.
Cause: The application failed to make a request to the Congress.gov API.
Solution: Check if the Congress.gov API key is valid and active. See API Connection Issues for more details.
Cause: The application failed to create the LLM client.
Solution: Check if the GenAI API key and URL are valid and active. See LLM Integration Issues for more details.
Cause: The LLM took too long to generate a response and the context deadline was exceeded.
Solution: Increase the timeout for LLM calls or optimize the prompts and context provided to the LLM. See LLM Integration Issues for more details.
The application logs to both the console and a log file (logs/http.log). You can view the logs to diagnose issues:
# View the log file
cat logs/http.log
# Follow the log file in real-time
tail -f logs/http.log
# Filter the log file for errors
grep ERROR logs/http.logWhen deployed to Cloud Foundry, you can view the logs using the cf logs command:
# View recent logs
cf logs congress-chatbot --recent
# Stream logs in real-time
cf logs congress-chatbotTo enable more detailed logging, you can set the DEBUG environment variable:
DEBUG=true go run cmd/server/main.goThis will enable more verbose logging, including detailed information about API calls and LLM interactions.
The application provides a health check endpoint at /api/health that can be used to verify that the application is running correctly:
curl http://localhost:8080/api/healthThe response should be:
{
"status": "ok",
"time": "2025-04-29T16:57:00Z"
}If the application is not running correctly, the health check endpoint may return an error or be unavailable.
To debug API calls, you can use the curl command to make requests directly to the Congress.gov API:
curl -H "X-API-Key: your_congress_api_key" https://api.congress.gov/v3/billThis can help determine if the issue is with the application or the API.
To debug LLM calls, you can use the curl command to make requests directly to the GenAI LLM service:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_GENAI_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, world!"}
]
}' \
your_GENAI_API_BASE_URL/chat/completionsThis can help determine if the issue is with the application or the LLM service.