Output Annotation state variable cannot be resolved #144

Closed
opened 2026-02-15 17:16:14 -05:00 by yindo · 7 comments
Owner

Originally created by @phuo1032 on GitHub (Dec 11, 2024).

Hi, I am trying out Input/Output schema to maintain state, following this guide
https://langchain-ai.github.io/langgraphjs/how-tos/input_output_schema/

annotation.ts (essentially a full copy paste from the guide)

import { Annotation, StateGraph } from "@langchain/langgraph";

const InputAnnotation = Annotation.Root({
  question: Annotation<string>,
});

const OutputAnnotation = Annotation.Root({
  answer: Annotation<string>,
});

const answerNode = (_state: typeof InputAnnotation.State) => {
  return { answer: "bye" };
};

const graphBuilder = new StateGraph({
  input: InputAnnotation,
  output: OutputAnnotation,
})
  .addNode("answerNode", answerNode)
  .addEdge("__start__", "answerNode")

export const annotation = graphBuilder.compile();

This works well in LangGraph studio. However, when I was trying to import this graph and invoke from another file

const output = await annotation.invoke({
    question: "hi",
  });
  console.log("\n=====START======\n");

  console.log("Answer: ", output.answer);

  console.log("\n=====END======\n");

I get an error
Property 'answer' does not exist on type 'StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.ts(2339)

It looks like it misinterprets the return value of graph invocation as input state object. The interesting thing is, if I just print out the output object I would see answer attribute exists. The code works fine but no compilable if I explicitly uses the state attributes.

I am using VSCode.

Originally created by @phuo1032 on GitHub (Dec 11, 2024). Hi, I am trying out Input/Output schema to maintain state, following this guide https://langchain-ai.github.io/langgraphjs/how-tos/input_output_schema/ annotation.ts (essentially a full copy paste from the guide) ``` import { Annotation, StateGraph } from "@langchain/langgraph"; const InputAnnotation = Annotation.Root({ question: Annotation<string>, }); const OutputAnnotation = Annotation.Root({ answer: Annotation<string>, }); const answerNode = (_state: typeof InputAnnotation.State) => { return { answer: "bye" }; }; const graphBuilder = new StateGraph({ input: InputAnnotation, output: OutputAnnotation, }) .addNode("answerNode", answerNode) .addEdge("__start__", "answerNode") export const annotation = graphBuilder.compile(); ``` This works well in LangGraph studio. However, when I was trying to import this graph and invoke from another file ``` const output = await annotation.invoke({ question: "hi", }); console.log("\n=====START======\n"); console.log("Answer: ", output.answer); console.log("\n=====END======\n"); ``` I get an error `Property 'answer' does not exist on type 'StateType<{ question: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.ts(2339)` It looks like it misinterprets the return value of graph invocation as input state object. The interesting thing is, if I just print out the **output** object I would see **answer** attribute exists. The code works fine but no compilable if I explicitly uses the state attributes. I am using VSCode.
yindo closed this issue 2026-02-15 17:16:14 -05:00
Author
Owner

@jacoblee93 commented on GitHub (Dec 11, 2024):

Thanks for reporting!

@dqbd could this be possibly related to https://github.com/langchain-ai/langgraphjs/pull/650?

@jacoblee93 commented on GitHub (Dec 11, 2024): Thanks for reporting! @dqbd could this be possibly related to https://github.com/langchain-ai/langgraphjs/pull/650?
Author
Owner

@phuo1032 commented on GitHub (Dec 11, 2024):

Not sure if this is related. There is a similar issue when I followed the Multiple Schema guide https://langchain-ai.github.io/langgraphjs/concepts/low_level/#multiple-schemas

I kept every single line of code

There is an error in this line:

 stateSchema: OverallStateAnnotation,
Type 'AnnotationRoot<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'AnnotationRoot<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
  Types of property 'Node' are incompatible.
    Type 'NodeType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
      Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'.
        Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'RunnableFunc<StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>, UpdateType<...> | Partial<...>, RunnableConfig<...>>'.
          Type 'StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>' is missing the following properties from type 'StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>': foo, bar, graph_outputts(2322)

Again it is running perfectly fine in LangGraph studio but not compilable with node natively.

@phuo1032 commented on GitHub (Dec 11, 2024): Not sure if this is related. There is a similar issue when I followed the Multiple Schema guide https://langchain-ai.github.io/langgraphjs/concepts/low_level/#multiple-schemas I kept every single line of code There is an error in this line: ``` stateSchema: OverallStateAnnotation, ``` ``` Type 'AnnotationRoot<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'AnnotationRoot<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Types of property 'Node' are incompatible. Type 'NodeType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'NodeType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>'. Type 'RunnableFunc<StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>, UpdateType<...> | Partial<...>, RunnableCon...' is not assignable to type 'RunnableFunc<StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>, UpdateType<...> | Partial<...>, RunnableConfig<...>>'. Type 'StateType<{ user_input: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; }>' is missing the following properties from type 'StateType<{ foo: { (): LastValue<string>; (annotation: SingleReducer<string, string>): BinaryOperatorAggregate<string, string>; Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<...>; }; bar: { ...; }; user_input: { ...; }; graph_output: { ...; }; }>': foo, bar, graph_outputts(2322) ``` Again it is running perfectly fine in LangGraph studio but not compilable with node natively.
Author
Owner

@jacoblee93 commented on GitHub (Dec 11, 2024):

Got it thanks for the heads up

Will cut a new version ASAP with the above PR. Can you try after upgrading?

@jacoblee93 commented on GitHub (Dec 11, 2024): Got it thanks for the heads up Will cut a new version ASAP with the above PR. Can you try after upgrading?
Author
Owner

@phuo1032 commented on GitHub (Dec 11, 2024):

I am happy to

@phuo1032 commented on GitHub (Dec 11, 2024): I am happy to
Author
Owner

@jacoblee93 commented on GitHub (Dec 11, 2024):

@phuo1032 can you try bumping to @langchain/langgraph@0.2.32?

@jacoblee93 commented on GitHub (Dec 11, 2024): @phuo1032 can you try bumping to `@langchain/langgraph@0.2.32`?
Author
Owner

@phuo1032 commented on GitHub (Dec 11, 2024):

Thank you. The first problem is addressed. But the second issue still exists. I'll open a separate issue instead.

@phuo1032 commented on GitHub (Dec 11, 2024): Thank you. The first problem is addressed. But the second issue still exists. I'll open a separate issue instead.
Author
Owner

@jacoblee93 commented on GitHub (Dec 11, 2024):

Thanks!

@jacoblee93 commented on GitHub (Dec 11, 2024): Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#144