Skip to content

Add structured outputs to Ask Mode#95

Merged
dannyjameswilliams merged 7 commits into
mainfrom
feat/structured_output
Jul 7, 2026
Merged

Add structured outputs to Ask Mode#95
dannyjameswilliams merged 7 commits into
mainfrom
feat/structured_output

Conversation

@dannyjameswilliams

Copy link
Copy Markdown
Contributor

Related to PR #1000 on the backend

Adds output_format parameter to .ask() and .ask_stream() methods to support structured responses.

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

Comment thread weaviate_agents/query/classes/response.py Outdated
Comment thread weaviate_agents/query/query_agent.py
Comment thread weaviate_agents/query/query_agent.py Outdated
Comment thread weaviate_agents/query/query_agent.py Outdated


class ParsedAskModeResponse(AskModeResponse, Generic[T]):
final_answer_parsed: SerializeAsAny[T]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dannyjameswilliams can you help me understand this?

You say the bound of the type is a dict or any BaseModel? What does that do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response. The bound lets a users own model flow through with their own fields intact, rather than just being a generic BaseModel/dict

So if the user inputs a basemodel, e.g.

class MyResponse(BaseModel):
    my_answer: str
    used_sources: list[UUID]
    
res = qa.ask(..., output_format=MyResponse)

then type checkers know to expect those fields in the response, so doing e.g.

res.final_answer_parsed.my_answer
res.final_answer_parsed.used_sources[0]

will be recognised as their respective types and so on.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it! Thanks so much! 🧠

@CShorten CShorten left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🔥

@dannyjameswilliams dannyjameswilliams merged commit 1da8c5a into main Jul 7, 2026
13 checks passed
@dannyjameswilliams dannyjameswilliams deleted the feat/structured_output branch July 7, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants