Find answers from the community

Updated 4 days ago

Can Llamaparse Extract Images From Pdfs And Insert Them In Json (structured Output)?

Can LlamaParse extract images from PDFs and insert them in JSON (structured output)?
L
A
8 comments
Its already in the JSON output πŸ‘€
For context, I'm trying to extract multiple choice questions (MCQs) from huge PDF files to JSON format, some questions contain images/tables that are required to be answered.

I tried to use structured output in the llamacloud but it didn't give any output, so I just used a system prompt with premium parsing.

I attached to you the markdown output of one of the questions in the PDF.
Attachments
image.png
image.png
Here is the prompt that I used:

Plain Text
Task: Extract and format multiple-choice questions (MCQs) from the provided text.

Instructions:

Extract only MCQs with a clear question stem and options labeled 'A.', 'B.', 'C.', etc. Ignore non-MCQ content.
Correct grammatical, spelling, and formatting errors in questions and options.
Translate any Arabic text to English while preserving meaning.
Remove duplicate and near-duplicate questions. For each unique question:
Track the number of duplicates ("duplicate_count").
Track how many times each option was chosen across duplicates ("count").
Determine the correct answer ("correctAnswer") from the source if provided, otherwise from the most commonly chosen option.
Associate images and tables with the nearest question. Include images (for exampe: img_p0_1.png) and tables as structured data in "media".
Assign a unique UUID to each question ("id").
Output the results in JSON format with the following structure:
{
  "questions": [
    {
      "id": "UUID",
      "question": "Question text",
      "options": [
        {"option": "A. Option text", "count": 0},
        {"option": "B. Option text", "count": 0}
      ],
      "correctAnswer": "A",
      "media": [
        {"type": "image", "data": "path to image"},
        {"type": "table", "data": "table data"}
      ],
      "duplicate_count": 1
    }
  ]
}
Notes:

Options must be labeled alphabetically (A., B., C., etc.).
Flag incomplete or ambiguous questions for review by adding a note in the "question" field (e.g., "[Flagged: Missing options]").
Maintain technical accuracy and clarity.
Oh its not possible to put image paths in the acutal structured output
the images are listed separately
what solution do you suggest for this issue?
is it possible to parse them into base64 for example?
I don't think there's any way to reference the output image in the actual text itself right now

Using the full raw json parse result though, you can get links to download the images, as well as layout information, so that could all be used to possibly stitch something together
Add a reply
Sign up and join the conversation on Discord