How I Fixed 2 Critical Bugs in My Second AI App (A Debugging Story)
How implementing try-except and if checks made my Streamlit app better.

Aspiring Generative AI and Agentic AI Developer with entry-level proficiency in Generative AI. My ambition is to help innovative companies build and deploy generative AI applications by using my skills in Python, LangChain, and agentic frameworks. Driven to apply the knowledge gained during my academic journey. Do you relate to my story, or want to know more about my background? I'd love to connect with you on LinkedIn! You can also reach me at 🔗linkedin.com/in/saiteja-puttoju 📧 saiteja.puttoju.ai@gmail.com
Hi everyone,
I'm continuing my journey in AI development! After building my first project (an AI Story Generator), I just finished my second one: VidNote AI, a YouTube summarizer.
It's a Streamlit app that takes a YouTube URL, fetches the transcript, and uses Google's Gemini AI to generate key topics and notes.
It worked perfectly on my machine. But when I tested it with tricky URLs (like invalid links or videos with disabled transcripts), it broke. It crashed, showed ugly errors, and sometimes... it even lied to the user. It was unprofessional, and I was frustrated.
Here's the Final App
After a lot of debugging, I'm happy to say it's now stable, robust, and user-friendly.
Here's a screenshot of the final, working app:

You can also see a full walkthrough and demo of the app in this video:
You can try the live demo for yourself!
➡️ Try the Live App: VidNote AI
➡️ See the Full Code: GitHub Repository
My Debugging Story: Fixing a "Lying" AI App
My app had two major flaws that made it look unprofessional.
I. The Problem (What Went Wrong)
1. The Ugly Crash:
When the youtube-transcript-api failed (e.g., "Request Blocked" or "Transcripts Disabled"), my app would crash. It printed the entire, long, and very un-user-friendly Python exception directly onto the Streamlit interface. It looked terrible.

2. The "Polite Lie":
This one was worse. In some cases, the API call would fail and return None (an empty value). My application didn't stop.
It would pass this empty transcript to the Gemini AI to generate "topics" and "notes." The AI would correctly state "The provided transcript is empty", but then my app would display a "✅ Generated notes successfully!" message right after it.
It was so confusing. It looked like the app was lying to the user.

II. The Investigation (How I Fixed It)
I realized I had two different problems:
An Exception Problem: I needed to catch those API errors before they crashed the app.
A Data Flow Problem: I should never call the AI if I don't have a transcript.
My solution had to be in two parts: one fix for the backend function, and one for the frontend logic.
III. The Solution (The Code)
Here is the exact two-part fix that made the app robust.
Part 1: Specific Exception Handling (The Backend Fix)
In my supporting_functions.py file, I wrapped the YouTubeTranscriptApi.fetch() call in a try...except block.
But instead of a generic except Exception, I specifically imported and caught the common errors from the library (like InvalidVideoId, TranscriptsDisabled, etc.). This allowed me to use st.error() to display a clean, user-friendly message for each specific problem.
Here's the code from supporting_functions.py:
# [Inside supporting_functions.py]
from youtube_transcript_api import YouTubeTranscriptApi, InvalidVideoId, TranscriptsDisabled, RequestBlocked, IpBlocked
import streamlit as st
def get_transcripts(video_id, language):
"""
Fetches youtube video transcriptions using video url and language code.
"""
ytt_api = YouTubeTranscriptApi()
try:
fetched_transcript = ytt_api.fetch(video_id=video_id, languages=[language])
transcript = " ".join([i.text for i in fetched_transcript])
time.sleep(10)
return transcript
# --- THIS IS THE FIX ---
except InvalidVideoId:
st.error("Invalid YouTube Video ID, please check the url once again")
except TranscriptsDisabled:
st.error("Transcripts are disabled for this video")
except RequestBlocked:
st.error("Request blocked by YouTube, please try again later")
except IpBlocked:
st.error("IP Blocked by YouTube, please try again later")
except Exception as e:
st.error(f"Error with fetching transcription: {e}")
This change completely stopped the app from crashing and showing ugly errors.
Part 2: Conditional Logic (The Frontend Fix)
This fix stopped the "lying" AI. In my main app.py file, I stopped the "bad data flow".
After calling full_transcript = get_transcripts(...), I added a simple conditional check: if full_transcript:.
All the AI-related logic (getting topics, generating notes) was moved inside this if block. This ensures that the AI functions are only called if a transcript was successfully fetched.
If full_transcript is None (meaning an error occurred and was handled by Part 1), it now runs an else: block and displays a single, clear message.
Here's the code from app.py:
# [Inside app.py]
with st.spinner("Step 1/3 : Fetching Video Transcripts..."):
full_transcript = get_transcripts(video_id, language)
if language != 'en':
# ... (translation logic) ...
pass
# --- THIS IS THE FIX ---
if full_transcript:
# All AI logic now goes inside this "if" block
with st.spinner("Step 2/3 : Fetching key topics..."):
topics = get_important_topics(full_transcript)
st.header("Key Topics: ")
st.info(topics)
with st.spinner("Step 3/3 : Generating Notes..."):
notes = generate_notes(full_transcript)
st.header("Notes: ")
st.write(notes)
st.success("✅ Generated notes successfully!")
else:
# This runs if full_transcript is None (i.e., an error happened)
st.info("Error in fetching transcripts, please try again!")
This simple if/else block made the user experience clean, honest, and professional.
What I Learned
By fixing these two bugs, I learned 3 important lessons as a new developer:
Always Handle Specific Exceptions: A generic
try-exceptis lazy. Catching specific errors (likeInvalidVideoIdorTranscriptsDisabled) is the professional way to help your users understand what went wrong.Check Your Data Flow: Never trust that a function will work. Always check the return value (like
if full_transcript:) before passing data to the next step—especially to an expensive AI model.The User Experience is Everything: An app that crashes is bad. An app that lies (even by accident) is worse. A simple, honest
st.info()message is 100x better than a confusing output.
Thank you for reading my debugging story!
All My Links
➡️ Try the Live App: https://ai-youtube-assistant-by-saiteja-puttoju.streamlit.app/
➡️ See the Full Code on GitHub: https://github.com/saiteja-puttoju/ai-youtube-assistant
➡️ Watch the Demo Video: https://youtu.be/4DsQDSz8Xnc
➡️ Connect with me on LinkedIn: https://www.linkedin.com/in/saiteja-puttoju/
What's the best way you've found to handle API errors in your Streamlit apps? Let me know in the comments!




