googleapis / googleapis/python-genai
Possible to return BOTH structured (application/json) and unstructured (markdown) output?
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
Is it possible for Gemini request to return BOTH structured (application/json) and unstructured (markdown) output in a single API call? The use case:
(1) Structured output for backend business logic process and DB persistence.
(2) Unstructured (markdown) to show it on the UI, maybe for human-in-the-loop validation of the data returned by the model.
For example, I have the following string / object returned:
```
{"message":"{\n \"date_str\": \"28-07-2017\",\n \"vendor\": \"Walmart\",\n \"currency\": \"USD\",\n \"items\": [\n {\n \"name\": \"PET TOY\",\n \"amount\": 1.97\n },\n {\n \"name\": \"FLOPPY PUPPY\",\n \"amount\": 1.97\n },\n {\n \"name\": \"SSSUPREME S\",\n \"amount\": 4.97\n },\n {\n \"name\": \"2.5 SQUEAK\",\n \"amount\": 5.92\n },\n {\n \"name\": \"MUNCHY DMBEL\",\n \"amount\": 3.77\n },\n {\n \"name\": \"DOG TREAT\",\n \"amount\": 2.92\n },\n {\n \"name\": \"PED PCH 1\",\n \"amount\": 0.50\n },\n {\n \"name\": \"PED PCH 1\",\n \"amount\": 0.50\n },\n {\n \"name\": \"COUPON 23100\",\n \"amount\": 1.00\n },\n {\n \"name\": \"HNYMD SMORES\",\n \"amount\": 3.98\n },\n {\n \"name\": \"FRENCH DRSNG\",\n \"amount\": 1.98\n },\n {\n \"name\": \"3 ORANGES\",\n \"amount\": 5.47\n },\n {\n \"name\": \"BABY CARROTS\",\n \"amount\": 1.48\n },\n {\n \"name\": \"COLLARDS\",\n \"amount\": 1.24\n },\n {\n \"name\": \"CALZONE\",\n \"amount\": 2.50\n },\n {\n \"name\": \"MM RVW MNT\",\n \"amount\": 19.77\n },\n {\n \"name\": \"STKOBRLPLABL\",\n \"amount\": 1.97\n },\n {\n \"name\": \"STKOBRLPLABL\",\n \"amount\": 1.97\n },\n {\n \"name\": \"STKO SUNFLWR\",\n \"amount\": 0.97\n },\n {\n \"name\": \"STKO SUNFLWR\",\n \"amount\": 0.97\n },\n {\n \"name\": \"STKO SUNFLWR\",\n \"amount\": 0.97\n },\n {\n \"name\": \"STKO SUNFLWR\",\n \"amount\": 0.97\n },\n {\n \"name\": \"BLING BEADS\",\n \"amount\": 0.97\n },\n {\n \"name\": \"GREAT VALUE\",\n \"amount\": 9.97\n },\n {\n \"name\": \"LIPTON\",\n \"amount\": 4.48\n },\n {\n \"name\": \"DRY DOG\",\n \"amount\": 12.44\n }\n ],\n \"tax\": 4.59,\n \"total\": 98.21\n}"}
```
and I try to use `showdown` javascript library to convert it to markdown and `makeHtml` but to no avail. What I get on the UI is only an unformatted json string and it is difficult to verify if the model has missed anything or introduced any hallunication in it's reasoning.
Contributor guide
Assessment
This issue has not been assessed yet.