DEV Community

Cover image for Building an LLM-Powered Knowledge Curation System
An-Ni Chen
An-Ni Chen

Posted on

Building an LLM-Powered Knowledge Curation System

Read the original post here

In our previous blog, "The Best Way to Generate Structured Output from LLMs", we explored the capabilities of OpenAI's Structured Outputs API by comparing it with tools like Langchain, BAML, and others. We demystified how format restrictions can negatively impact Large Language Models (LLMs) and introduced a multi-step approach using Instill VDP to navigate these challenges.

Today, we're exploring the bigger picture of how OpenAI's Structured Outputs API can be combined with applications to build powerful end-to-end pipelines, enabling developers to leverage JSON schemas to enhance field completeness and boost the reliability of downstream tasks. As we aim for stable LLM integration in production environments, this tutorial will walk you through how to build an LLM-powered knowledge curation system and equip you with essential tips and best practices.

Building an LLM-Powered Knowledge Curation System

Let's create a tool to automate web research and summarization, transforming
online data into structured insights:

  1. Searches Google with your query
  2. Scrapes the top result's content into Markdown-formatted text
  3. Summarizes information in a pre-defined structured format

Try it Yourself!

Click the links below to view and try these pipelines out for yourself - for free - on the Instill Cloud platform!

Try Instill Cloud ☁️

Step-by-Step Tutorial

We will use OpenAI's Structued Outputs and Instill VDP to build our LLM-powered knowledge curation pipeline. Watch this video for a step-by-step guide

Prerequisites

Create an account on Instill Cloud by following the steps here.

Step 1: Configure Google Search & API key

To start using the Google Search Component on Instill VDP, you will need to first create an API key. See Google Search Setup docs for more details.

  1. Go to Programmable Search Engine control panel and create a new Search Engine ID

Configurations for Google's Programmable Search Engine

  1. Once created, click Customize to see your Search engine ID
  2. Copy the Search engine ID for later
  3. Go to Google's Custom Search JSON API documentation
  4. Click Get a Key to generate your API key
  5. Copy the API key for later

You can further explore Advanced Programmable Search Engine features to refine search features depending on your use case such as safe search, restrict region, filter images, sort result, etc.

Step 2: Create a new pipeline

  1. Go to Instill Cloud and find your Pipelines tab in the top left
  2. Click + Create Pipeline in the top right to enter the pipeline editor

Recipe editor (left), pipeline preview & input/output (right)

Step 3: Add Google Search and query

In the pipeline recipe, add input variables:

variable:
  google-cse-id:
    title: CSE ID
    description: ID of search engine to use
    instill-format: string
  search-query:
    title: Search Query
    description: the Google search query
    instill-format: string
Enter fullscreen mode Exit fullscreen mode

Add Google Search Component:

component:
  google:
    type: google-search
    task: TASK_SEARCH
    input:
      include-link-html: false
      include-link-text: false
      query: ${variable.search-query}
      top-k: 10
    setup:
      api-key: ${secret.google-search-api-key}
      cse-id: ${variable.google-cse-id}
Enter fullscreen mode Exit fullscreen mode

Please create and store your Google Search API key securely in Secrets by following the steps in our Secret Management docs for best practices.

Step 4: Scrape website content

Add a Web Component and select scrape webpage task

  • set include-html to true
  • set only-main-content to true
  • set url to reference google variable as shown below
scraper:
  type: web
  task: TASK_SCRAPE_WEBPAGE
  input:
    include-html: true
    only-main-content: true
    url: ${google.output.results[0].link}
Enter fullscreen mode Exit fullscreen mode

Step 5: Summarize the scraped content

Add an OpenAI Component to summarize the page content

  • set the model to use gpt-4o-mini
  • set temperature to 0
  • set the prompt as shown below
  • set the system-message as shown below
extract-and-summarize:
  type: openai
  task: TASK_TEXT_GENERATION
  input:
    model: gpt-4o-mini
    n: 1
    prompt: |-
      You are given the content of a scraped website. Analyze the content and summarize the key insights that are relevant to the user's search query.

      **Search Query**:
      ${variable.search-query}

      **Website Content**:
      ${scraper.output.markdown}

      **Website URL**:
      ${google.output.results[0].link}

      Now generate your response, providing an output for each of the steps:
    response-format:
      type: text
    system-message: |-
      You are a helpful assistant.

      Follow these steps and instructions to generate your response:
      1. Write a brief summary of the content
      2. Extract the title of the content
      3. Identify the source (e.g., website name)
      4. List the key insights from the content
      5. Extract the author's name (if available)
      6. Mention the published date (if available)
      7. Identify any relevant keywords, tags or topics discussed
    temperature: 0
    top-p: 1
  setup:
    api-key: ${secret.INSTILL_SECRET}
Enter fullscreen mode Exit fullscreen mode

Step 6: Structure the output

Add another OpenAI component to structure the output

  • set the model to use gpt-4o-2024-08-06
  • set temperature to 0
  • set the response-fomat > type to json_schema
  • add json-schema as shown below
  • set the prompt as shown below
structure-response:
  type: openai
  task: TASK_TEXT_GENERATION
  input:
    model: gpt-4o-2024-08-06
    n: 1
    prompt: |-
      Extract from this content: ${extract-and-summarize.output.texts[0]}
      URL: ${google.output.results[0].link}
    response-format:
      json-schema: |
        {
          "name": "structured_content",
          "description": "Extracts, summarizes and structures information from a webpage",
          "strict": true,
          "schema": {
            "type": "object",
            "properties": {
              "summary": {
                "type": "string",
                "description": "A brief summary of the content"
              },
              "title": {
                "type": "string",
                "description": "Title of the webpage"
              },
              "url": {
                "type": "string",
                "description": "Webpage URL"
              },
              "source": {
                "type": "string",
                "description": "The source of the content (e.g., website name)"
              },
              "author": {
                "type": "string",
                "description": "Author's name (if available)"
              },
              "published_date": {
                "type": "string",
                "description": "Published data (if available)"
              },
              "tags": {
                "type": "array",
                "description": "Relevant keywords, tags or topics discussed",
                "items": {
                  "type": "string"
                }
              },
              "key_insights": {
                "type": "array",
                "description": "A list of key insights from the content",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "summary",
              "title",
              "url",
              "source",
              "author",
              "published_date",
              "tags",
              "key_insights"
            ],
            "additionalProperties": false
          }
        }
      type: json_schema
    system-message: You are a helpful assistant.
    temperature: 0
    top-p: 1
  setup:
    api-key: ${secret.INSTILL_SECRET}
Enter fullscreen mode Exit fullscreen mode

Add a JSON component to output the result as json

text-to-json:
  type: json
  task: TASK_UNMARSHAL
  input:
    string: ${structure-response.output.texts[0]}

Enter fullscreen mode Exit fullscreen mode

Finally, output the result by adding this to the end of the recipe

output:
  scraped-content:
    title: Content
    value: ${scraper.output.markdown}
  structured-output:
    title: Structured web-search summary
    value: ${text-to-json.output.json}
Enter fullscreen mode Exit fullscreen mode

Step 7: Run the pipeline

There are a few ways you can run a pipeline, see Run Pipeline docs.

1. Run pipeline via editor

In the Input form on the bottom right, fill in the corresponding values:

CSE ID: <Your Search Engine ID>
Search Query: What are the risks of lasik?
Enter fullscreen mode Exit fullscreen mode

Run pipeline in editor

2. Run pipeline via API

To generate your Instill API Token, see the API Token Management docs.

export INSTILL_API_TOKEN='**********'

curl -X POST 'https://api.instill.tech/v1beta/organizations/instill-ai/pipelines/structured-web-insights/trigger' \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $INSTILL_API_TOKEN" \
--data '{
  "inputs": [
    {
      "google-cse-id": <YOUR CSE ID>,
      "search-query": "What are the risks of lasik?"
    }
  ]
}'
Enter fullscreen mode Exit fullscreen mode
{
  "outputs": [
    {
      "scraped-content": "LASIK eye surgery - Mayo Clinic\n\nThis content does not have an English version.\n\nThis content does not have an Arabic version.\n\n[Print](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/about/pac-20384774?p=1)\n\n## Overview\n\n![LASIK eye surgery](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2016/05/05/15/20/mcdc7_lasik-6col.jpg)\nLASIK surgery\nEnlarge image\n\nClose\n\n### LASIK surgery\n\n![LASIK eye surgery](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2016/05/05/15/20/mcdc7_lasik-6col.jpg)\n\n### LASIK surgery\n\nDuring LASIK eye surgery, an eye surgeon creates a flap in the cornea — the transparent, dome-shaped surface of the eye that accounts for a large part of the eye's bending or refracting power (A). Then the surgeon uses a laser to reshape the cornea, which corrects the refraction problems in the eye (B). The flap is then put back in place (C).\n\nLASIK eye surgery is the best known and most commonly performed laser refractive surgery to correct vision problems. Laser-assisted in situ keratomileusis (LASIK) can be an alternative to glasses or contact lenses.\n\nDuring LASIK surgery, a special type of cutting laser is used to change the shape of the cornea. The cornea is the dome-shaped clear tissue at the front of the eye.\n\nIn eyes with typical vision, the cornea bends — or refracts — light precisely onto the retina at the back of the eye. But with nearsightedness, farsightedness or astigmatism, the light is bent incorrectly. This incorrect refraction causes blurred vision.\n\nGlasses or contact lenses can correct vision, but reshaping the cornea also provides the refraction needed to correct vision.\n\n### Products & Services\n\n- [A Book: Mayo Clinic Guide to Better Vision](https://order.store.mayoclinic.com/flex/mmv/vison01/?utm_source=MC-DotOrg-PS&utm_medium=Link&utm_campaign=Vision-Book&utm_content=VIS)\n\n## Why it's done\n\n![Anatomy of the eye](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2013/11/15/17/42/ds00230_-ds00233_-ds00254_-ds00527_-ds00528_-ds00786_-ds01128_-my00376_-my00491_-wl00010_im02853_r7_eyethu_jpg.jpg)\nAnatomy of the eye\nEnlarge image\n\nClose\n\n### Anatomy of the eye\n\n![Anatomy of the eye](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2013/11/15/17/42/ds00230_-ds00233_-ds00254_-ds00527_-ds00528_-ds00786_-ds01128_-my00376_-my00491_-wl00010_im02853_r7_eyethu_jpg.jpg)\n\n### Anatomy of the eye\n\nYour eye is a complex and compact structure measuring about 1 inch (2.5 centimeters) in diameter. It receives millions of pieces of information about the outside world, which are quickly processed by your brain.\n\n![Nearsightedness (myopia)](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2014/02/24/18/41/r7_myopia.jpg)\nNearsightedness (myopia)\nEnlarge image\n\nClose\n\n### Nearsightedness (myopia)\n\n![Nearsightedness (myopia)](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2014/02/24/18/41/r7_myopia.jpg)\n\n### Nearsightedness (myopia)\n\nWith typical vision, an image is sharply focused onto the surface of the retina. In nearsightedness, the point of focus is in front of the retina, making distant objects appear blurry.\n\n![Farsightedness (hyperopia)](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2013/11/15/17/38/ds00527_-my00376_im01545_r7_hyperopiathu_jpg.png)\nFarsightedness (hyperopia)\nEnlarge image\n\nClose\n\n### Farsightedness (hyperopia)\n\n![Farsightedness (hyperopia)](http://www.mayoclinic.org/-/media/kcms/gbs/patient-consumer/images/2013/11/15/17/38/ds00527_-my00376_im01545_r7_hyperopiathu_jpg.png)\n\n### Farsightedness (hyperopia)\n\nWith typical vision, an image is sharply focused onto the surface of the retina. In farsightedness, the point of focus falls behind the retina, making close-up objects appear blurry.\n\nLASIK surgery may be an option for the correction of these vision problems:\n\n- **Nearsightedness, also called myopia.** In nearsightedness, your eyeball is slightly longer than typical or the cornea curves too sharply. This causes light rays to focus in front of the retina, which makes distant vision blurry. Objects that are close can be seen fairly clearly. But objects in the distance will be blurry.\n- **Farsightedness, also called hyperopia.** In farsightedness, you have a shorter than average eyeball or a cornea that is too flat. This causes light to focus behind the retina instead of on it. This makes near vision, and sometimes distant vision, blurry.\n- **Astigmatism.** In astigmatism, the cornea curves or flattens unevenly. This affects focus of near and distant vision.\n\nIf you're considering LASIK surgery, you probably already wear glasses or contact lenses. Your eye doctor will talk with you about whether LASIK surgery or another similar refractive procedure is an option that will work for you.\n\n[Request an appointment](http://www.mayoclinic.org/appointments)\n\n## Risks\n\nComplications that result in a loss of vision are very rare. But certain side effects of LASIK eye surgery are common. These include dry eyes and temporary visual problems such as glare. These symptoms usually clear up after a few weeks or months. Few people consider them to be a long-term problem.\n\nRisks of LASIK surgery include:\n\n- **Dry eyes.** LASIK surgery causes a temporary decrease in tear production. For the first six months or so after your surgery, your eyes may feel unusually dry as they heal. Dry eyes can reduce the quality of your vision.\n\nYour eye doctor might recommend eye drops for dry eyes. If you experience severe dry eyes, your eye doctor may recommend additional management, including tear drain plugs or medicated eye drops.\n\n- **Glare, halos and double vision.** You may have a hard time seeing at night after surgery. This usually lasts a few days to a few weeks. You might notice increased light sensitivity, glare, halos around bright lights or double vision.\n\nEven when a good visual result is measured under standard testing conditions, your vision in dim light (such as at dusk or in fog) may be reduced to a greater degree after the surgery than before the surgery.\n\n- **Undercorrections.** If the laser removes too little tissue from your eye, you won't get the clearer vision results you were hoping for. Undercorrections are more common for people who are nearsighted. You may need another LASIK procedure within a year to remove more tissue.\n- **Overcorrections.** It's also possible that the laser will remove too much tissue from your eye. Overcorrections may be more difficult to fix than undercorrections.\n- **Astigmatism.** Astigmatism can be caused by uneven tissue removal. It may require another surgery, glasses or contact lenses.\n- **Flap problems.** Folding back or removing the flap from the front of your eye during surgery can cause complications, including infection and excess tears. The outermost corneal tissue layer may grow abnormally underneath the flap during the healing process.\n- **Corneal ectasia.** Corneal ectasia, a condition in which the cornea is too thin and weak, is one of the more-serious complications. The abnormal cornea tissue is unable to maintain its shape, which can lead to cornea bulging and worsening vision.\n- **Regression.** Regression is when your vision slowly changes back toward your original prescription. This is a less common complication.\n- **Vision loss or changes.** Rarely, surgical complications can result in loss of vision. Some people also may not see as sharply or clearly as previously.\n\n### Conditions that increase risks\n\nCertain health conditions can increase the risks associated with LASIK surgery or make the outcome less predictable.\n\nDoctors may not recommend laser refractive surgery for you if you have certain conditions, including:\n\n- Autoimmune disorders, such as rheumatoid arthritis.\n- A weakened immune system caused by immunosuppressive medications or HIV.\n- Constantly dry eyes.\n- Recent changes in vision due to medicines, hormonal changes, pregnancy, breastfeeding or age.\n- Inflammation of the cornea, lid disorders, eye injuries or eye diseases, such as uveitis, herpes simplex affecting the eye area, glaucoma or cataracts.\n- Disorders of the cornea, including keratoconus or corneal ectasia.\n\nLASIK surgery is usually not recommended if you:\n\n- Have an eye disease that causes the cornea to thin and bulge, such as keratoconus.\n- Have a family history of keratoconus or other corneal ectasia.\n- Have good overall vision.\n- Have severe nearsightedness.\n- Have very large pupils or thin corneas.\n- Have age-related eye changes that cause vision to be less clear.\n- Participate in contact sports that may be associated with blows to the face.\n\nIf you're considering LASIK surgery, talk to your doctor about your questions and concerns. Your doctor will discuss whether you're a candidate for the procedure or other similar procedures.\n\n## How you prepare\n\nSteps you can take to prepare for surgery include:\n\n- **Know what surgery may cost you.** LASIK surgery is usually considered elective surgery, so most insurance companies won't cover the cost of the surgery. Be prepared to pay out-of-pocket for your expenses.\n- **Arrange for a ride home.** You'll need to have someone drive you to and from your place of surgery. Immediately after surgery, you might still feel the effects of medicine given to you before surgery, and your vision may be blurry.\n- **Skip the eye makeup.** Don't use eye makeup, cream, perfumes or lotions on the day before and the day of your surgery. Your doctor may also tell you to clean your eyelashes daily or more often in the days leading up to surgery. This helps remove debris and lessens your risk of infection.\n\n## What you can expect\n\n### Before the procedure\n\nLong-term results from LASIK tend to be best in people who are carefully checked before surgery to see if they are good candidates for the procedure.\n\nIf you wear contact lenses, you'll need to stop wearing them and wear only your glasses for at least a few weeks before your evaluation and surgery. This is because contact lenses can change the shape of your cornea. Your eye doctor will provide specific guidelines depending on the type of contacts you wear and how long you've been a contact lens wearer.\n\nDuring the evaluation, your eye doctor will ask about your medical and surgical history and give you a complete eye examination to check your vision and decide whether you can undergo the procedure safely.\n\nYour eye doctor will look for signs of:\n\n- Eye infection.\n- Inflammation.\n- Dry eyes.\n- Large pupils.\n- High eye pressure.\n\nYour eye doctor will also measure your cornea, noting the shape, contour, thickness and any irregularities. Your eye doctor will check which areas of your cornea need reshaping and determine the exact amount of tissue to remove from your cornea.\n\nDoctors generally use wavefront-guided technology to check your eye in detail before LASIK surgery. In this test, a scanner creates a highly detailed chart, similar to a topographic map, of your eye. The more detailed the measurements, the more accurate your eye doctor can be in removing corneal tissue.\n\nBefore surgery, your doctor will discuss the risks and benefits of LASIK surgery, what to expect before and after surgery, and any questions you may have.\n\n### During the procedure\n\nLASIK surgery is usually completed in 30 minutes or less. During the procedure, you lie on your back in a reclining chair. You may be given medicine to help you relax. After numbing drops are placed in your eye, your doctor uses an instrument to hold your eyelids open.\n\nA suction ring is placed on your eye just before cutting the corneal flap. This may cause a feeling of pressure, and your vision may dim a little.\n\nYour eye surgeon uses a small blade or cutting laser to cut a small hinged flap away from the front of your eye. Folding back the flap allows your doctor to reach the part of your cornea to be reshaped.\n\nUsing a programmed laser, your eye surgeon reshapes parts of your cornea. With each pulse of the laser beam, a tiny amount of corneal tissue is removed. After reshaping the cornea, the surgeon lays the flap back into place. The flap usually heals without stitches.\n\nDuring the surgery, you'll be asked to focus on a point of light. Staring at this light helps you keep your eye fixed while the laser reshapes your cornea. You may notice a distinct odor as the laser removes your corneal tissue. Some people describe smelling an odor similar to that of burning hair.\n\nIf you need LASIK surgery in both eyes, doctors will generally do the procedure on the same day.\n\n#### Video: LASIK eye surgery\n\nShow transcriptfor video Video: LASIK eye surgery\n\nLASIK surgery is performed with a laser programmed to remove a defined amount of tissue from a part of your eye called the cornea.\n\nTo begin, your doctor uses a special blade — or laser — to cut a flap on the top layer of your cornea, about the size of a contact lens. The flap allows access to the deeper layers of your eye.\n\nThe laser is used again to flatten certain tissue or to make the tissue steeper, depending on your needs for corrected vision. Finally, the flap is folded back into place and will heal on its own.\n\n### After the procedure\n\nImmediately after surgery, your eye might itch, feel gritty, burn and be watery. You'll probably have blurred vision. You generally will experience little pain, and you'll usually recover your vision quickly.\n\nYou might be given pain medicine or eye drops to keep you comfortable for several hours after the procedure. Your eye doctor might also ask you to wear a shield over your eye at night until your eye heals.\n\nYou'll be able to see after surgery, but your vision won't be clear right away. While vision after LASIK is generally good within a few days, it can be up to 2 to 3 months after your surgery before your eye heals completely and your vision stabilizes. Your chances for improved vision are based, in part, on how good your vision was before surgery.\n\nYou'll have a follow-up appointment with your eye doctor 1 to 2 days after surgery. This is to see how your eye is healing and check for any complications. Plan for other follow-up appointments during the first six months after surgery as your doctor recommends.\n\nIt might be a few weeks before you can start to use cosmetics around your eyes again. You also might have to wait several weeks before resuming strenuous contact sports, swimming or using hot tubs.\n\nFollow your doctor's recommendations about how soon you can resume your usual activities.\n\n## Results\n\nLASIK often offers improved vision without the hassle of glasses or contact lenses. In general, you have a very good chance of achieving 20/40 vision or better after refractive surgery.\n\nMore than 8 out of 10 people who've undergone LASIK refractive surgery no longer need to use their glasses or contact lenses for most of their activities.\n\nYour results depend on your specific refractive error and other factors. People with a low grade of nearsightedness tend to have the most success with refractive surgery. People with a high degree of nearsightedness or farsightedness along with astigmatism have less predictable results.\n\nIn some cases, the surgery might result in undercorrection. If this happens, you might need another surgery to achieve the proper correction.\n\nRarely, some people's eyes slowly return to the level of vision they had before surgery. This might happen due to certain conditions, such as problems with wound healing, hormonal imbalances or pregnancy. Sometimes this change in vision is due to another eye problem, such as a cataract. Talk with your doctor about any vision changes.\n\n[By Mayo Clinic Staff](http://www.mayoclinic.org/about-this-site/meet-our-medical-editors)\n\n[LASIK eye surgery care at Mayo Clinic](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/care-at-mayo-clinic/pcc-20384776)\n\n[Request an appointment](http://www.mayoclinic.org/appointments)\n\n[Doctors & Departments](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/doctors-departments/pdc-20384775)\n\nAug. 02, 2023\n\n[Print](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/about/pac-20384774?p=1)\n\nShow references\n\n1. Stein HA, et al., eds. Refractive surgery: Today and the future. In: Ophthalmic Assistant. 11th ed. Elsevier; 2023. https://www.clinicalkey.com. Accessed April 5, 2023.\n2. AskMayoExpert. Refractive laser surgery (adult). Mayo Clinic; 2022.\n3. Yanoff M, et al., eds. Laser-assisted in situ keratomileusis (LASIK). In: Ophthalmology. 6th ed. Elsevier; 2023. https://www.clinicalkey.com. Accessed April 5, 2023.\n4. Surgery for refractive errors. National Eye Institute. https://www.nei.nih.gov/learn-about-eye-health/eye-conditions-and-diseases/refractive-errors/surgery-refractive-errors. Accessed April 5, 2023.\n5. When is LASIK not for me? U.S. Food and Drug Administration. https://www.fda.gov/medical-devices/lasik/when-lasik-not-me. Accessed March 22, 2023.\n6. What should I expect before, during, and after surgery? U.S. Food and Drug Administration. https://www.fda.gov/medical-devices/lasik/what-should-i-expect-during-and-after-surgery#top. Accessed March 22, 2023.\n7. Mannis MJ, et al., eds. LASIK for myopia. In: Cornea: Fundamentals, Diagnosis and Management. 5th ed. Elsevier; 2022. https://www.clinicalkey.com. Accessed April 5, 2023.\n8. Chodnicki KD (expert opinion). Mayo Clinic. April 9, 2023.\n\n## Related\n\n- [Anatomy of the eye](http://www.mayoclinic.org/healthy-lifestyle/adult-health/multimedia/anatomy-of-the-eye/img-20008178)\n- [Astigmatism](http://www.mayoclinic.org/diseases-conditions/astigmatism/symptoms-causes/syc-20353835)\n- [Considering LASIK surgery](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/in-depth/lasik-surgery/art-20045751)\n- [Farsightedness](http://www.mayoclinic.org/diseases-conditions/farsightedness/symptoms-causes/syc-20372495)\n- [Farsightedness (hyperopia)](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/multimedia/farsightedness-hyperopia/img-20006711)\n- [Illustration of LASIK eye surgery](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/multimedia/illustration-of-lasik-eye-surgery/img-20007640)\n- [LASIK eye surgery](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/multimedia/lasik-eye-surgery/vid-20084660)\n- [Nearsightedness](http://www.mayoclinic.org/diseases-conditions/nearsightedness/symptoms-causes/syc-20375556)\n- [Nearsightedness (myopia)](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/multimedia/nearsightedness-myopia/img-20006068)\n- [Presbyopia](http://www.mayoclinic.org/diseases-conditions/presbyopia/symptoms-causes/syc-20363328)\n\nShow more related content\n\n### Products & Services\n\n- [A Book: Mayo Clinic Guide to Better Vision](https://order.store.mayoclinic.com/flex/mmv/vison01/?utm_source=MC-DotOrg-PS&utm_medium=Link&utm_campaign=Vision-Book&utm_content=VIS)\n\n## LASIK eye surgery\n\n- [About](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/about/pac-20384774)\n- [Doctors\\\n\\\n&\\\n\\\nDepartments](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/doctors-departments/pdc-20384775)\n- [Care at\\\n\\\nMayo\\\n\\\nClinic](http://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/care-at-mayo-clinic/pcc-20384776)\n\nAdvertisement\n\nMayo Clinic does not endorse companies or products. Advertising revenue supports our not-for-profit mission.\n\n**Advertising & Sponsorship**\n\n- [Policy](http://www.mayoclinic.org/about-this-site/advertising-sponsorship-policy)\n- [Opportunities](http://www.mayoclinic.org/about-this-site/advertising-sponsorship)\n- [Ad Choices](https://optout.aboutads.info/)\n\n### Mayo Clinic Press\n\nCheck out these best-sellers and special offers on books and newsletters from [Mayo Clinic Press](https://mcpress.mayoclinic.org/?utm_source=MC-DotOrg-Text&utm_medium=Link&utm_campaign=MC-Press&utm_content=MCPRESS).\n\n- [Mayo Clinic on Incontinence - Mayo Clinic PressMayo Clinic on Incontinence](https://order.store.mayoclinic.com/flex/mmv/incon01/?altkey=INMCPRC&utm_source=MC-DotOrg-Text&utm_medium=Link&utm_campaign=Incontinence-Book&utm_content=INC)\n- [The Essential Diabetes Book - Mayo Clinic PressThe Essential Diabetes Book](https://order.store.mayoclinic.com/flex/mmv/ESDIAB1/?altkey=ESMCPRC&utm_source=MC-DotOrg-Text&utm_medium=Link&utm_campaign=Diabetes-Book&utm_content=EDIAB)\n- [Mayo Clinic on Hearing and Balance - Mayo Clinic PressMayo Clinic on Hearing and Balance](https://order.store.mayoclinic.com/flex/mmv/HRBAL02/?altkey=HRMCPRC&utm_source=MC-DotOrg-Text&utm_medium=Link&utm_campaign=Hearing-Book&utm_content=HEAR)\n- [FREE Mayo Clinic Diet Assessment - Mayo Clinic PressFREE Mayo Clinic Diet Assessment](https://diet.mayoclinic.org/us/diet-assessment/diet-assessment/?profile=true&promo=65-qtr&utm_source=Mayo&utm_medium=Display&utm_campaign=text_link)\n- [Mayo Clinic Health Letter - FREE book - Mayo Clinic PressMayo Clinic Health Letter - FREE book](https://order.store.mayoclinic.com/hl/HLFREEB?utm_source=MC-DotOrg-Text&utm_medium=Link&utm_campaign=HealthLetter-Digital&utm_content=HL_FREEBOOK)\n\nPRC-20194006\n\n- [Patient Care & Health Information](http://www.mayoclinic.org/patient-care-and-health-information)\n- [Tests & Procedures](http://www.mayoclinic.org/tests-procedures)\n- LASIK eye surgery\n\n![](https://assets.mayoclinic.org/content/dam/media/global/images/2023/11/14/giving-charity.svg)\n\n## 5X Challenge\n\n[Give Today](https://philanthropy.mayoclinic.org/page.aspx?pid=1833&sourcecode=24R081WI5MWV90Z24B&utm_source=devorgtilead&utm_medium=devweb&utm_campaign=dev5xchallenge)\n\nThanks to generous benefactors, your gift today can have 5X the impact to advance AI innovation at Mayo Clinic.\n\n[Give Today](https://philanthropy.mayoclinic.org/page.aspx?pid=1833&sourcecode=24R081WI5MWV90Z24B&utm_source=devorgtilead&utm_medium=devweb&utm_campaign=dev5xchallenge)",
      "structured-output": {
        "author": "Mayo Clinic Staff",
        "key_insights": [
          "LASIK is a common laser refractive surgery aimed at correcting vision problems such as nearsightedness, farsightedness, and astigmatism.",
          "Common side effects include dry eyes, glare, halos, and temporary visual disturbances, which usually resolve over time.",
          "Serious risks include undercorrections, overcorrections, astigmatism, flap complications, corneal ectasia, regression of vision, and rare cases of vision loss.",
          "Certain health conditions can increase the risks associated with LASIK, such as autoimmune disorders, dry eyes, and specific eye diseases."
        ],
        "published_date": "August 02, 2023",
        "source": "Mayo Clinic",
        "summary": "The content from the Mayo Clinic provides an overview of LASIK eye surgery, detailing the procedure, its purpose, and the potential risks involved. It highlights common side effects such as dry eyes, glare, and visual disturbances, as well as more serious complications like corneal ectasia and vision loss. The article also discusses conditions that may increase the risks associated with LASIK and emphasizes the importance of consulting with a doctor before proceeding with the surgery.",
        "tags": [
          "LASIK",
          "eye surgery",
          "vision correction",
          "risks",
          "side effects",
          "nearsightedness",
          "farsightedness",
          "astigmatism",
          "corneal ectasia",
          "dry eyes",
          "glare",
          "visual disturbances"
        ],
        "title": "LASIK eye surgery - Mayo Clinic",
        "url": "https://www.mayoclinic.org/tests-procedures/lasik-eye-surgery/about/pac-20384774"
      }
    }
  ],
  "metadata": {
    ...
  }
}
Enter fullscreen mode Exit fullscreen mode

It's also easy to trigger these pipelines from a Python environment with our Python SDK, and you can launch an accompanying Colab notebook to this tutorial with the button below:

Try in Colab 🚀

Tips & Learning Outcomes

  1. Prefer OpenAI's Structured Outputs single shot accuracy

    • Generates valid JSON in one attempt, reducing API calls and saving resources
    • More efficient than alternatives like Instructor, Marvin, or TypeChat
  2. Choose the Right Model

    • Use gpt-4o-2024-08-06 for complex schemas
    • Use gpt-4o-mini for simpler structures, saving costs and decreasing latency
  3. Add helpful descriptions to each schema entry to improve final output accuracy

"schema": {
  "type": "object",
  "properties": {
    "summary": {
      "type": "string",
      "description": "A brief summary of the content" <---- helpful description for the LLM
    },
  ...
Enter fullscreen mode Exit fullscreen mode
  1. Set temperature depending on your use case
    • 0 for deterministic outcomes, suitable for reasoning & structuring tasks
    • 1 for creative outcome variations, suitable for content generation tasks

Finally, the pipeline we have built in this tutorial can be useful in various real-world applications, such as:

  • Research Aggregation: Collecting information from multiple sources on a specific topic and presenting it in a clean, structured format can save time for users by providing a consolidated summary.

  • Market Intelligence: Businesses can use this to monitor competitors, trends, or pricing information across various sites, presented in a structured and actionable format.

  • News Summarization: Journalists and media organizations could use such a tool to track breaking news or trending topics, summarized in a digestible, predefined structure.

  • Sentiment Analysis: It can be applied to pull reviews, comments, or opinions from multiple sources (e.g., social media, forums), and present a structured sentiment analysis.

  • Data Extraction & Transformation: For legal, technical, or regulatory documents, such a pipeline could gather and organize content from trusted websites into structured legalese or a database.

Next steps

Now that you've mastered building a pipeline with OpenAI's Structured Outputs, consider modifying this use case for more specific applications.

For more ideas:

If you have any questions or build anything cool, do share it with us on
Discord or @instill_tech on X/Twitter!

Join Discord ✨

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.