<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sreedharlal B Naick on Medium]]></title>
        <description><![CDATA[Stories by Sreedharlal B Naick on Medium]]></description>
        <link>https://medium.com/@sreedharlal.b.naick?source=rss-a262db0c83da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*i9Ks45fMFVKk16W_D-9oig.jpeg</url>
            <title>Stories by Sreedharlal B Naick on Medium</title>
            <link>https://medium.com/@sreedharlal.b.naick?source=rss-a262db0c83da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 22:09:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sreedharlal.b.naick/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Receipts to Actions: Function Calling in Gemini]]></title>
            <link>https://medium.com/@sreedharlal.b.naick/from-receipts-to-actions-function-calling-in-gemini-faeac5ee4808?source=rss-a262db0c83da------2</link>
            <guid isPermaLink="false">https://medium.com/p/faeac5ee4808</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[llm-function-calling]]></category>
            <dc:creator><![CDATA[Sreedharlal B Naick]]></dc:creator>
            <pubDate>Wed, 07 May 2025 12:03:24 GMT</pubDate>
            <atom:updated>2025-05-07T13:28:37.904Z</atom:updated>
            <content:encoded><![CDATA[<p>In my <a href="https://medium.com/@sreedharlal.b.naick/turning-receipts-into-structured-data-using-gemini-multimodality-c191ec959dec">previous article</a>, I shared how I used Gemini’s multimodal capabilities to convert receipts into structured JSONs. That project solved one part of the problem — <strong>understanding</strong>.</p><p>The next natural step? Use this structured data to automate the process of creating expenses in Zoho Books — without writing custom rules for every edge case.</p><h3>Course</h3><p>To go deeper, I took the next course in the GenAI Exchange series: <a href="https://www.cloudskillsboost.google/course_templates/959?catalog_rank=%7B%22rank%22%3A1%2C%22num_filters%22%3A1%2C%22has_search%22%3Atrue%7D&amp;search_id=42101250">Explore Generative AI with the Gemini API in Vertex AI</a>.</p><p>Key things I learned:</p><ul><li>Multimodal understanding and processing using Gemini</li><li>How to use Gemini’s Function Calling to structure output and trigger actions</li><li>How to chain model responses</li></ul><p>This unlocked a major shift: from just extracting data to taking <strong>action</strong> on it.</p><h3>Function Calling: Powering Autonomous Decision Making</h3><p><a href="https://ai.google.dev/gemini-api/docs/function-calling">Function calling</a> allows Gemini to go beyond static output. Instead of asking the model for a response and writing the logic yourself, you define what actions are possible — and Gemini decides which one to take.</p><p>This approach transforms how we build workflows:</p><ul><li>The control flow becomes <strong>model-driven</strong>, not developer-managed.</li><li>You can add new capabilities just by <strong>defining additional functions</strong> — without rewriting the core logic.</li><li>It’s a foundation for building <strong>autonomous agents</strong> that reason, plan, and execute.</li></ul><p>Let’s take our expense creation case: when processing a receipt, the agent must decide:</p><ul><li>Check if the vendor (from the receipt) already exists.</li><li>If it exists: fetch the vendor ID and create an expense.</li><li>If it doesn’t: create a new vendor, get its ID, and then create the expense.</li></ul><p>This decision tree, traditionally done in code, can beoffloaded to the model. With function calling, Gemini can infer the right steps and sequence of actions — entirely based on input and context.</p><h3>Automating Vendor Detection and Expense Creation</h3><p>I defined three functions — get_vendor, create_vendor, and create_expense — following the Gemini SDK documentation.</p><p>Here’s one example:</p><pre>def get_function_declaration(cls):<br>    return {<br>        &quot;name&quot;: &quot;create_vendor&quot;,<br>        &quot;description&quot;: &quot;Creates a new vendor with name and GST number&quot;,<br>        &quot;parameters&quot;: {<br>            &quot;type&quot;: &quot;object&quot;,<br>            &quot;properties&quot;: {<br>                &quot;vendor_name&quot;: {<br>                    &quot;type&quot;: &quot;string&quot;,<br>                    &quot;description&quot;: &quot;Name of the vendor&quot;,<br>                },<br>                &quot;gst_number&quot;: {<br>                    &quot;type&quot;: &quot;string&quot;,<br>                    &quot;description&quot;: &quot;GST number of the vendor&quot;,<br>                },<br>            },<br>            &quot;required&quot;: [&quot;vendor_name&quot;, &quot;gst_number&quot;],<br>        },<br>    }</pre><p>And updated the prompt to:</p><pre>prompt = f&quot;&quot;&quot;<br>    Task:<br>    Analyze the following invoice, provided context and create an expense entry. <br>    <br>    Instructions:<br>    - Before creating the expense entry, you need to get the vendor ID.<br>    - If the vendor does not exist, you need to create the vendor first and then create the expense entry. <br>    - Always start with getting the vendor ID.<br><br>    Based on the invoice content, decide which function to call and with what parameters.<br>    &quot;&quot;&quot;</pre><p>Then invoked the Gemini API with tools like this:</p><pre>function_declarations = [<br>        CreateVendor.get_function_declaration(),<br>        GetVendor.get_function_declaration(),<br>        CreateExpense.get_function_declaration(),<br>    ]<br>tools = [types.Tool(function_declarations=function_declarations)]<br><br>config = genai.types.GenerateContentConfig(<br>    tools=tools,<br>    automatic_function_calling=genai.types.AutomaticFunctionCallingConfig(<br>        disable=True<br>    ),<br>)<br><br>response = self.client.models.generate_content(<br>    model=&quot;gemini-2.0-flash&quot;, contents=contents, config=config<br>)</pre><p>This setup allows Gemini to determine which function to invoke based on the user’s input. As I scale the system, I can keep adding new functions — Gemini handles the routing logic.</p><h3>Orchestrating the Flow</h3><p>To go from single-shot function execution to a <strong>multi-step, stateful agent</strong>, I extended my earlier flow to support <strong>looping and dynamic decision-making</strong>.</p><p>Here’s what I changed:</p><ul><li><strong>Introduced a </strong><strong>Decide node</strong> that takes the output from Gemini and routes to the appropriate tool based on the selected function.</li><li><strong>Enabled branching</strong> using PocketFlow’s node &gt;&gt; tool syntax to jump between nodes</li><li><strong>Closed the loop</strong> by routing each tool’s output back to the Decide node — allowing Gemini to reason over intermediate results and determine the next step dynamically.</li></ul><p>This looping structure is what transforms the flow into a true <strong>agent loop</strong> — allowing the model to pause, evaluate, and decide the next action until the task is complete.</p><pre>upload = Upload()<br>prepare = Prepare()<br>decide = Decide(tools=tools)<br>get_vendor = GetVendor()<br>create_vendor = CreateVendor()<br>create_expense = CreateExpense()<br><br>upload &gt;&gt; prepare &gt;&gt; decide<br><br># Connect the nodes<br># If DecideAction returns &quot;get_vendor&quot;, go to GetVendor<br>decide - &quot;get_vendor&quot; &gt;&gt; get_vendor<br><br># If DecideAction returns &quot;create_vendor&quot;, go to CreateVendor<br>decide - &quot;create_vendor&quot; &gt;&gt; create_vendor<br><br># If DecideAction returns &quot;create_expense&quot;, go to CreateExpense<br>decide - &quot;create_expense&quot; &gt;&gt; create_expense<br><br># After GetVendor completes and returns &quot;decide&quot;, go back to DecideAction<br>get_vendor - &quot;decide&quot; &gt;&gt; decide<br><br># After CreateVendor completes and returns &quot;decide&quot;, go back to DecideAction<br>create_vendor - &quot;decide&quot; &gt;&gt; decide<br><br># Create and run the flow<br>flow = Flow(start=upload)<br>flow.run(shared)</pre><h3>Result</h3><p>To test the loop, I ran two sample flows:</p><ol><li><strong>Vendor not found:</strong> Since the get_vendor function was mocked to return “vendor does not exist,” the agent automatically invoked create_vendor, got the new vendor ID, and proceeded to create_expense.</li><li><strong>Vendor exists:</strong> By hardcoding a vendor ID in get_vendor, the agent skipped vendor creation and directly called create_expense.</li></ol><p>Note:</p><p>The table in the app screenshot shows a step-by-step interaction between the <strong>Gemini model</strong> and the <strong>app</strong>, using function calling:</p><ul><li><strong>model</strong> rows represent the model deciding what function to call next, based on reasoning over previous results.</li><li><strong>app</strong> rows show the actual response from the app/backend after executing that function.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeEMVJdq8mzmDN9cQpl_bg.png" /><figcaption>when get_vendor returns ‘vendor does not exist’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bNAQh2D86-rVSP17MAQe6Q.png" /><figcaption>when get_vendor returns vendor_id</figcaption></figure><p>This validated the agent’s ability to reason over intermediate results and dynamically choose the correct path — all without any manual control logic.</p><h3>What’s Next?</h3><ul><li>Enable automatic function execution with Gemini SDK</li><li>Integrate with Zoho Books API</li><li>Make design scalable to add more tools/functions</li></ul><p>I’m excited by how fast things are evolving — and how concepts like structured output, function calling, and orchestration are blending into true agent architectures.</p><p>Stay tuned as I build this into a complete Expense Intelligence Bot for our startup. Follow for updates and reach out if you’re building something similar!</p><p>Refer this <a href="https://github.com/sreedharlal-b-naick/zoho-expense-creator/commit/06eab47ce2d6f9287ed246f97f82dde6f051bc85">commit</a> on <a href="https://github.com/sreedharlal-b-naick/zoho-expense-creator">GitHub Repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=faeac5ee4808" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Turning Receipts into Structured Data Using Gemini Multimodality]]></title>
            <link>https://medium.com/@sreedharlal.b.naick/turning-receipts-into-structured-data-using-gemini-multimodality-c191ec959dec?source=rss-a262db0c83da------2</link>
            <guid isPermaLink="false">https://medium.com/p/c191ec959dec</guid>
            <dc:creator><![CDATA[Sreedharlal B Naick]]></dc:creator>
            <pubDate>Sat, 03 May 2025 04:58:52 GMT</pubDate>
            <atom:updated>2025-05-07T12:00:48.455Z</atom:updated>
            <content:encoded><![CDATA[<p>In the last few weeks, I’ve been on a hands-on journey exploring Generative AI through two foundational courses. Those experiences led to building a basic SQL query extractor using Gemini APIs, Streamlit, and PocketFlow. That project is still evolving, but my curiosity got the better of me — I wanted to explore something beyond text.</p><p>How does multimodality — working with images and PDFs — fit into this GenAI wave? Can it help in practical business workflows?</p><h3>The Course That Sparked It</h3><p>The next course I took as part of the Google GenAI Exchange program was <strong><em>Inspect Rich Documents with Gemini Multimodality and Multimodal RAG</em></strong>. It introduced me to a completely new side of Gemini — one that goes beyond just handling text to understanding images, videos, and complex documents.</p><p>Some highlights:</p><ul><li>Prompt Gemini with both <strong>text and images/videos</strong></li><li>Perform <strong>visual reasoning</strong>, object recognition, and semantic analysis</li><li>Build <strong>multimodal RAG systems</strong> that search and answer using image+text context</li></ul><p>What really stood out was how simple the API made it to interact with visual data. No fine-tuning or complex ML pipelines — just structured prompting and smart usage of Gemini’s models.</p><h3>The Project Idea: Expense Entry from Image/PDF</h3><p>Like always, I wanted to apply these learnings to something close to our workflow.</p><p>Our team frequently handles expenses like metro tickets, food bills from client visits, and vendor or infrastructure payments. Whether it’s sales logging receipts or me uploading utility invoices, we all spend time manually entering details into Zoho Books. It’s tedious and error-prone — felt like something GenAI could simplify.</p><p>What if they could just drop an image or PDF into an app — and that’s it? The app reads everything and fills the expense entry automatically. That’s how this experiment started.</p><h3>Framework and Setup</h3><p>I decided to stick to the same stack:</p><ul><li><strong>PocketFlow</strong> for structuring the app into flows and steps</li><li><strong>Gemini API</strong> for multimodal intelligence</li><li><strong>Streamlit</strong> for a clean and interactive UI</li></ul><p>I copied the .cursorules from my previous SQL extractor project, bootstrapped a new app, and asked Cursor to generate some basic scaffolding: accept file upload, parse content using Gemini, and display the extracted results.</p><h3>Reading and Understanding Images</h3><p>Gemini can analyze images and answer questions about them or extract structured data. I followed the documentation: <a href="https://ai.google.dev/gemini-api/docs/image-understanding">Image Understanding with Gemini</a></p><p>Initially, I used a simple prompt asking Gemini to return a JSON output. While it worked, I realized there was a more efficient way to define and structure the data. Instead of just requesting a raw JSON, I leveraged <a href="https://ai.google.dev/gemini-api/docs/structured-output?lang=python">Structured Output with Gemini</a> by using Pydantic models. This allowed me to better define the exact format I wanted, making the entire process more robust and efficient.</p><p>Here’s the Expense model I defined:</p><pre>from pydantic import BaseModel, Field<br><br><br>class Expense(BaseModel):<br>    date: str = Field(description=&quot;The date of the expense in YYYY-MM-DD format&quot;)<br>    amount: float = Field(<br>        description=&quot;The total expense amount as a number (no currency symbol)&quot;<br>    )<br>    vendor: str = Field(description=&quot;The name of the vendor or company&quot;)<br>    expense_type: str = Field(<br>        description=&quot;A brief category like &#39;Travel&#39;, &#39;Meals&#39;, &#39;Office Supplies&#39;, etc.&quot;<br>    )</pre><p>The following code demonstrates how I extract expense information from receipts or invoices using Gemini:</p><pre>from google import genai<br>from google.genai import types<br><br>client = genai.Client(api_key=api_key)<br>prompt = f&quot;&quot;&quot;Analyze the following invoice image and extract the expense details&quot;&quot;&quot;<br><br>try:<br>    # Read the image file<br>    with open(image_path, &quot;rb&quot;) as f:<br>        image_bytes = f.read()<br><br>    # Create image part<br>    image_part = types.Part.from_bytes(data=image_bytes, mime_type=&quot;image/jpeg&quot;)<br><br>    # Generate content with image and prompt<br>    response = client.models.generate_content(<br>        model=&quot;gemini-2.0-flash&quot;,<br>        contents=[image_part, prompt],<br>        config={<br>            &quot;response_mime_type&quot;: &quot;application/json&quot;,<br>            &quot;response_schema&quot;: Expense,<br>        },<br>    )<br><br>    return json.loads(response.text)<br>except Exception as e:<br>    raise Exception(f&quot;Error processing image: {str(e)}&quot;)</pre><p>And here’s a sample screenshot showing how the app extracted expense details from a bus ticket:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nf7cYAnSL6bQ9EnTgF05-Q.png" /></figure><h3>Reading and Parsing PDFs</h3><p>I extended the app to support PDF invoices by following the guide: <a href="https://ai.google.dev/gemini-api/docs/document-processing?lang=python">Document Processing with Gemini</a>. Worked smoothly for most 1–2 page PDFs.</p><p>Here’s a snippet of the code I used to extract data from the PDF:</p><pre>from google import genai<br>from google.genai import types<br>from pathlib import Path<br><br>client = genai.Client(api_key=api_key)<br>prompt = f&quot;&quot;&quot;Analyze the following PDF document and extract the expense details.  &quot;&quot;&quot;<br><br>try:<br>    # Convert string path to Path object<br>    filepath = Path(file_path)<br><br>    file_part = types.Part.from_bytes(<br>        data=filepath.read_bytes(),<br>        mime_type=&quot;application/pdf&quot;,<br>    )<br><br>    # Generate content with PDF and prompt<br>    response = client.models.generate_content(<br>        model=&quot;gemini-2.0-flash&quot;,<br>        contents=[file_part, prompt],<br>        config={<br>            &quot;response_mime_type&quot;: &quot;application/json&quot;,<br>            &quot;response_schema&quot;: Expense,<br>        },<br>    )<br><br>    return json.loads(response.text)<br><br>except Exception as e:<br>    raise Exception(f&quot;Error processing PDF: {str(e)}&quot;)</pre><p>And here’s a screenshot of the extracted information from a nameboard receipt:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Rp9yld_B89l5WKadC_yqw.png" /></figure><h3>What’s Next?</h3><p>This is still the MVP. I’ve tried it with a handful of sample images and PDFs, but there’s a lot to test.</p><p>Also I’ll continue this journey in the next post where I’ll explore:</p><ul><li>Build logic for <strong>function calling</strong> to prepare expense entries</li><li>Integrate with <strong>Zoho Books API</strong> to auto-create expenses</li><li>Possibly deploy internally for our team to try it out</li></ul><p>Stay tuned!</p><p>Check out <a href="https://github.com/sreedharlal-b-naick/zoho-expense-creator/commit/fe1160d767de59bfa69bf67ebe4e1aefdf4942d2">extract from image or pdf file</a> commint on <a href="https://github.com/sreedharlal-b-naick/zoho-expense-creator">github repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c191ec959dec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building SQL Extractor using PocketFlow, Gemini & Streamlit]]></title>
            <link>https://medium.com/@sreedharlal.b.naick/building-sql-extractor-using-pocketflow-gemini-streamlit-60fd6fedfbeb?source=rss-a262db0c83da------2</link>
            <guid isPermaLink="false">https://medium.com/p/60fd6fedfbeb</guid>
            <category><![CDATA[llm-applications]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Sreedharlal B Naick]]></dc:creator>
            <pubDate>Wed, 30 Apr 2025 11:29:22 GMT</pubDate>
            <atom:updated>2025-04-30T13:04:52.516Z</atom:updated>
            <content:encoded><![CDATA[<p>In the <a href="https://medium.com/@sreedharlal.b.naick/prompt-engineering-best-practices-4d6406845422">previous post</a>, I talked about fine-tuning a prompt to reliably extract SQL queries from source code. But building the <strong>actual working app</strong> around that prompt? That’s a whole different beast.</p><p>This post is about how I built that full-fledged app: from learning the tools to making agentic coding work like magic.</p><h3>Learning to Build LLM Apps</h3><p>To get the foundations right, I took the <strong>“Develop GenAI Apps with Gemini and Streamlit”</strong> course from Google Cloud Skills Boost. It wasn’t just a quick-start. It covered:</p><ul><li>Use Gemini via API and generating outputs from multimodal prompts</li><li>Function calling and structured output</li><li>Deployment using Streamlit + Cloud Run (a powerful combo for fast iteration)</li></ul><p>The course helped me understand how to think in terms of input/output pipelines, agent flows, and production-grade app deployment.</p><h3>Choosing a Framework</h3><p>Thanks to the course, I got comfortable with Gemini and Streamlit. I decided to continue with both for the app. Now I needed an orchestration framework. There are several excellent options out there: LangChain, LlamaIndex, PocketFlow and more. After exploring first three, I decided to start with <a href="https://github.com/The-Pocket/PocketFlow"><strong>PocketFlow</strong></a>.</p><p>Why PocketFlow?</p><ul><li>Lightweight: Just 100 lines. Zero bloat, zero dependencies, zero vendor lock-in.</li><li>Simple to use. Less learning curve.</li><li>Agentic coding with Cursor rules is 🔥</li></ul><p>💡 <strong>Pro Tip</strong>: If you’re building your first agent-based app, check out the official <a href="https://github.com/The-Pocket/PocketFlow-Template-Python">PocketFlow Python template</a>.</p><h3>Agentic Coding: Let AI Build the App</h3><p>PocketFlow is designed for AI agents like <strong>Cursor AI</strong> to help you build agents. Basically, you give it a design prompt + file structure, and it bootstraps your agents.</p><p>I created a basic project skeleton using poetry for dependency management, typer for CLI support and created basic files referring <a href="https://github.com/The-Pocket/PocketFlow-Tutorial-Codebase-Knowledge">PocketFlow-Tutorial-Codebase-Knowledge</a>.</p><p>Then I asked Cursor:</p><blockquote><em>Generate a detailed design for an SQL extractor which can filter relevant files from Github/Local repository, search for SQL codes, extract the SQL query and metadata using LLM and collect all queries and save a json file. Use PocketFlow for orchestration.</em></blockquote><p>Cursor replied with a solid multi-node flow, covering everything I had in mind. I asked it to generate the rest of the files following my structure. I had to make a few manual fixes and adjustments, but the boost in speed was real.</p><p>Here’s the flow definition it produced:</p><pre># flow.py<br><br>def create_extract_flow() -&gt; Flow:<br>    &quot;&quot;&quot;<br>    Create and return the SQL query extraction flow.<br>    &quot;&quot;&quot;<br>    fetch = FetchRepository()<br>    extract = ExtractQueries()<br>    process = ProcessQueries()<br>    generate = GenerateOutput()<br><br>    fetch &gt;&gt; extract &gt;&gt; process &gt;&gt; generate<br><br>    return Flow(start=fetch)</pre><p>This function sets up the full extraction pipeline using PocketFlow by linking four steps — fetching the repository, extracting SQL, processing queries, and generating the final output. The &gt;&gt; operator chains these steps together into a seamless flow that begins with fetching the code..</p><p>Simple, readable, and powerful.</p><p>💡 <strong>Pro Tip</strong>: Prime Cursor by giving it some starting files. I created flow.py, utils/call_llm.py, and a dummy FetchRepository node before asking it to generate the rest.</p><h3>Integrating Gemini AI</h3><p>Next, it was time for the LLM integration. I generated an API key for Gemini AI from <a href="https://aistudio.google.com/app/apikey">AI Studio</a>, installed the openai Python package, and <em>viola</em>—I was able to extract SQL queries from code within my local directory.</p><p>I extended the initial generated code to add an abstraction layer, supporting multiple LLM providers for flexibility. Here’s a snippet of how I integrated Gemini AI, enabling the extraction of SQL queries:</p><pre>class LLMProvider(ABC):<br>    &quot;&quot;&quot;Abstract base class for LLM providers&quot;&quot;&quot;<br>    <br>    def __init__(self, api_key: str = None, **kwargs):<br>        &quot;&quot;&quot;Initialize the LLM provider with configuration&quot;&quot;&quot;<br>        self.client = OpenAI(<br>            base_url=self.BASE_URL,<br>            api_key=api_key<br>        )<br>        self.model = kwargs.get(&#39;model&#39;, self.DEFAULT_MODEL)<br>        self.temperature = kwargs.get(&#39;temperature&#39;, 0.0)<br>    <br>    def call(self, instruction: str, prompt: str, **kwargs) -&gt; str:<br>        &quot;&quot;&quot;Call the LLM with the given instruction and prompt&quot;&quot;&quot;<br>        response = self.client.chat.completions.create(<br>            model=self.model,<br>            messages=[<br>                {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: instruction},<br>                {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: prompt}<br>            ],<br>            temperature=self.temperature<br>        )<br>        return response.choices[0].message.content<br><br>class GeminiProvider(LLMProvider):<br>    &quot;&quot;&quot;Provider for Google Gemini LLM service&quot;&quot;&quot;<br>    BASE_URL = &quot;https://generativelanguage.googleapis.com/v1beta/openai/&quot;<br>    DEFAULT_MODEL = &#39;gemini-2.0-flash&#39;<br>    <br>    def __init__(self, api_key: str = None, **kwargs):<br>        super().__init__(<br>            api_key=api_key,<br>            **kwargs<br>        )</pre><h3>Adding Streamlit UI</h3><p>Once the flow was tested and working, I added Streamlit support. Again, I used agentic coding to generate the UI scaffolding. And my SQL extractor app was ready to use!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*08jFX9YVTRuR6KkZsBS6Sw.png" /><figcaption>Streamlit App UI</figcaption></figure><h3>Final Thoughts</h3><p>This was a deeply satisfying build. I learned a lot — about orchestrating agent flows with PocketFlow, integrating Gemini LLMs using the OpenAI-compatible API, and leveraging agentic coding to accelerate development. It was my first time building a tool like this from scratch using these components, and getting it to work end-to-end was a great checkpoint.</p><p>But make no mistake — the app is far from finished. Right now, it works well for extracting basic SQL from straightforward codebases. However, there’s still a long road ahead. Some of the key improvements on the roadmap:</p><ul><li><strong>Supporting ORM frameworks</strong> like SQLAlchemy etc.</li><li><strong>Reasoning over missing context</strong>, where SQL queries are constructed across functions or modules.</li><li><strong>Evaluation and testing</strong>: Measuring extraction quality and adding automated tests.</li><li><strong>Better context retrieval</strong>: Using embeddings to find related logic scattered across files.</li></ul><p>More updates will definitely follow — especially when I start integrating this into our SQL assistant at Dalade. That’s when real-world usage will start exposing both edge cases and opportunities to push this further.</p><p>So stay tuned. There’s a lot more to come.</p><p>Checkout the GitHub Repository: <a href="https://github.com/sreedharlal-b-naick/sql-extractor">github.com/sreedharlal-b-naick/sql-extractor</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60fd6fedfbeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prompt Engineering Best Practices]]></title>
            <link>https://medium.com/@sreedharlal.b.naick/prompt-engineering-best-practices-4d6406845422?source=rss-a262db0c83da------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d6406845422</guid>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <dc:creator><![CDATA[Sreedharlal B Naick]]></dc:creator>
            <pubDate>Tue, 29 Apr 2025 05:19:37 GMT</pubDate>
            <atom:updated>2025-04-29T05:19:37.560Z</atom:updated>
            <content:encoded><![CDATA[<p>In the past few weeks, I’ve been diving deep into GenAI through the <a href="https://vision.hack2skill.com/event/genaiexchange">Google Gen AI Exchange Program</a> — learning about LLMs, prompt engineering, and platforms like Vertex AI.</p><p>In this article, I’ll walk you through the process of how I evolved a basic prompt to a more <strong>robust, production-ready prompt</strong> using <strong>best practices in prompt engineering</strong>.</p><h3>Backstory</h3><p>At our startup <strong>Dalade</strong>, we’re on a mission to explore how GenAI can power our existing products — or even spark entirely new ones. Before we build customer-facing applications, we knew it was essential to learn by building something for ourselves — after all, nothing beats learning by doing.</p><p>Our sales and product teams rely on the development team to write SQL queries for customer insights. This approach works, but it has a downside — it introduces delays when new features are needed. So, we decided to build an <strong>SQL Assistant</strong> that allows non-technical team members to get data via natural language queries.</p><p>As I started building the assistant, I realised that testing, evaluating and fine-tuning it required <strong>lots of sample SQL queries</strong>. This led me to develop an <strong>SQL Extractor Agent</strong> that could pull SQL queries from our <strong>GitHub repositories</strong>, making it easier to generate sample data set.</p><h3>From Basic to Better: Crafting the Right Prompt</h3><p>The agent first crawls all files, identifies code with SQL queries and extract using LLM. At first, the prompt for this was simple and looked like:</p><pre>&quot;&quot;&quot;<br>Analyze the following code and extract query with metadata in JSON format:<br>{code}<br><br>Please provide the following information:<br>1. name (name of the query)<br>2. description (brief description of what the query does)<br>3. query (extracted sql query)<br><br>Return ONLY the JSON object, no additional text.<br>&quot;&quot;&quot;</pre><p>While this worked, it wasn’t perfect. The model sometimes added extra text, or the response wasn’t always in valid JSON. I had to apply the key principles learned in <strong>Prompt Design in Vertex AI</strong> course, for improving my prompts.</p><h3>Prompt Engineering Best Practices</h3><h3>1. Be Specific &amp; Well-Defined</h3><p>Instead of just asking the model to extract the SQL query, I gave it clear instructions on the output format, like:</p><pre>&quot;&quot;&quot;<br>Instructions:<br>  - Provide a JSON object with:<br>      1. &quot;name&quot; — an appropriate name for the query<br>      2. &quot;description&quot; — a concise description of what the query does<br>      3. &quot;query&quot; — the extracted Postgres SQL query<br>  - Return ONLY the JSON object. No additional explanations.<br>  - Ensure the output is:<br>      - Valid, directly parseable JSON<br>      - Free from escape sequences like \\_ or \\*<br>      - Not wrapped inside markdown or code blocks<br><br>Avoid:<br>  - Adding introductory text or commentary<br>  - Incorrect JSON formats<br>&quot;&quot;&quot;<br></pre><h3>2. Use System Roles</h3><p>I included a <strong>system role</strong> to guide the model on how to behave. For example:instruction = &quot;You are a helpful assistant expert in extracting SQL queries in structured JSON format from code accurately.&quot;</p><pre>&quot;&quot;&quot;<br>You are a helpful assistant expert in extracting SQL queries in structured JSON format from code accurately.<br>&quot;&quot;&quot;</pre><h3>3. Temperature Control</h3><p>I adjusted the <strong>temperature</strong> to <strong>0</strong> to reduce randomness and ensure predictable, structured responses.</p><h3>4. Example-Driven Prompting</h3><p>I added example in the prompt to give the model a clear idea of what it was supposed to return. This not only improved the results but also made the prompt more robust.</p><pre>&quot;&quot;&quot;<br>Example:<br>  {{<br>  &quot;name&quot;: &quot;Insert student&quot;,<br>  &quot;description&quot;: &quot;Inserts a new student record into the database&quot;,<br>  &quot;query&quot;: &quot;INSERT INTO students (name, age, gender) VALUES (&#39;name&#39;, 25, &#39;M&#39;)&quot;<br>  }}<br>&quot;&quot;&quot;</pre><h3>The Final Prompt</h3><p>Here’s the updated version of the prompt:</p><pre>&quot;&quot;&quot;<br>You are a helpful assistant expert in extracting SQL queries in structured JSON format from code accurately.<br><br>Task:<br>Analyze the following code and extract the Postgres SQL query along with metadata in JSON format:<br>{code}<br><br>Instructions:<br>- Provide a JSON object with:<br>    1. &quot;name&quot; — an appropriate name for the query<br>    2. &quot;description&quot; — a concise description of what the query does<br>    3. &quot;query&quot; — the extracted Postgres SQL query<br>- Return ONLY the JSON object. No additional explanations.<br>- Ensure the output is:<br>    - Valid, directly parseable JSON<br>    - Free from escape sequences like \\_ or \\*<br>    - Not wrapped inside markdown or code blocks<br><br>Example:<br>  {{<br>    &quot;name&quot;: &quot;Insert student&quot;,<br>    &quot;description&quot;: &quot;Inserts a new student record into the database&quot;,<br>    &quot;query&quot;: &quot;INSERT INTO students (name, age, gender) VALUES (&#39;name&#39;, 25, &#39;M&#39;)&quot;<br>  }}<br><br>Avoid:<br>- Adding introductory text or commentary<br>- Incorrect JSON formats<br>&quot;&quot;&quot;</pre><h3>Conclusion</h3><p>By applying <strong>best practices in prompt engineering</strong>, I was able to improve the quality, consistency, and reliability of the SQL queries and metadata extracted by the LLM agent.</p><p><strong>Key Takeaways:</strong></p><ul><li><strong>Prompt engineering</strong> plays a huge role in maximizing LLM potential.</li><li><strong>Clear instructions and system roles</strong> improve output quality.</li><li>Use <strong>examples</strong> and <strong>temperature control</strong> to make prompts more reliable and predictable.</li></ul><p>As I continue building GenAI-based solutions at Dalade, I’ll keep sharing my learnings and best practices with the community. I hope these insights help you optimize your own LLM-powered applications!</p><p>#GenAI #AIForBuilders #PromptEngineering #LLM #AIApplications #MachineLearning #VertexAI #LearningByBuilding #DataAutomation #SQLAssistant</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d6406845422" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>