Skip to content

feat(llm): support structured output in AnthropicLLM via response_format#530

Open
SAY-5 wants to merge 1 commit into
neo4j:mainfrom
SAY-5:feat/anthropic-structured-output
Open

feat(llm): support structured output in AnthropicLLM via response_format#530
SAY-5 wants to merge 1 commit into
neo4j:mainfrom
SAY-5:feat/anthropic-structured-output

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 19, 2026

Copy link
Copy Markdown

Description

Closes #493. AnthropicLLM.invoke/ainvoke previously raised NotImplementedError for response_format; this adds structured output support so AnthropicLLM works alongside OpenAILLM and VertexAILLM. A Pydantic model is converted to a JSON schema and a passthrough dict is also accepted, both forwarded as Anthropic's output_config; behavior is unchanged when response_format is omitted. The issue is labelled help wanted and good first issue by the maintainers, and the request is "to add structured output support for AnthropicLLM alongside OpenAILLM and VertexLLM providers".

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update
  • Project configuration change

Complexity

Complexity: Low

How Has This Been Tested?

  • Unit tests
  • E2E tests
  • Manual tests

Checklist

The following requirements should have been met (depending on the changes in the branch):

  • Documentation has been updated
  • Unit tests have been updated
  • E2E tests have been updated
  • Examples have been updated
  • New files have copyright header
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated if appropriate

@SAY-5 SAY-5 requested a review from a team as a code owner May 19, 2026 07:28
@NathalieCharbel NathalieCharbel self-assigned this May 28, 2026

@NathalieCharbel NathalieCharbel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @SAY-5 for your contribution!

This looks really great. Apart from the non-blocking comments, I also suggest to:

  • update the documentation to add an Anthropic sub-section along side VertexAI and OpenAI
  • (Nice to have) update examples directory with an anthropic_llm_structured_output.py example showing a simple example of how we can use SO with anthropic models), for consistency with vertexai_llm_structured_output.py and openai_llm_structured_output.py


assert response.content == "plain response"
call_args = _as_mock(llm.client.messages.create).call_args[1]
assert "output_config" not in call_args

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would be good to also mirror the checks on ["format"]["type"] from the async test below

raise ImportError(
"""Could not import Anthropic Python client.
Please install it with `pip install "neo4j-graphrag[anthropic]"`."""
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should also enable supports_structured_output flag (same as we do with OpenAILLM and VertexAILLM now that this interface supports structured output:

supports_structured_output: bool = True

@NathalieCharbel

Copy link
Copy Markdown
Contributor

@SAY-5 Can you also please make sure to sign CLA?

@NathalieCharbel

Copy link
Copy Markdown
Contributor

@SAY-5 The PR is approved and we're excited to get it merged. As a friendly reminder, we still need the CLA signature before we can merge it.

If you're short on time, we can take care of the remaining unblocking comments on our side. Thanks in advance for your help, and we'd appreciate a quick response from your end.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5 SAY-5 force-pushed the feat/anthropic-structured-output branch from 8b17a05 to e74aaf0 Compare June 26, 2026 21:34
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.

[FEATURE]: Add Anthropic's Structured Output feature

2 participants