@@ -551,12 +551,14 @@ class MyOutput:
551551 )
552552 ),
553553 'final_result' : '{"content": "a"}' ,
554+ 'gen_ai.system_instructions' : '[{"type": "text", "content": "Here are some instructions"}]' ,
554555 'logfire.json_schema' : IsJson (
555556 snapshot (
556557 {
557558 'type' : 'object' ,
558559 'properties' : {
559560 'pydantic_ai.all_messages' : {'type' : 'array' },
561+ 'gen_ai.system_instructions' : {'type' : 'array' },
560562 'final_result' : {'type' : 'object' },
561563 },
562564 }
@@ -692,6 +694,140 @@ class MyOutput:
692694 )
693695
694696
697+ @pytest .mark .skipif (not logfire_installed , reason = 'logfire not installed' )
698+ def test_instructions_with_structured_output_exclude_content_v2 (
699+ get_logfire_summary : Callable [[], LogfireSummary ],
700+ ) -> None :
701+ @dataclass
702+ class MyOutput :
703+ content : str
704+
705+ settings : InstrumentationSettings = InstrumentationSettings (include_content = False , version = 2 )
706+
707+ my_agent = Agent (model = TestModel (), instructions = 'Here are some instructions' , instrument = settings )
708+
709+ result = my_agent .run_sync ('Hello' , output_type = MyOutput )
710+ assert result .output == snapshot (MyOutput (content = 'a' ))
711+
712+ summary = get_logfire_summary ()
713+ assert summary .attributes [0 ] == snapshot (
714+ {
715+ 'model_name' : 'test' ,
716+ 'agent_name' : 'my_agent' ,
717+ 'logfire.msg' : 'my_agent run' ,
718+ 'logfire.span_type' : 'span' ,
719+ 'gen_ai.usage.input_tokens' : 51 ,
720+ 'gen_ai.usage.output_tokens' : 5 ,
721+ 'pydantic_ai.all_messages' : IsJson (
722+ snapshot (
723+ [
724+ {'role' : 'user' , 'parts' : [{'type' : 'text' }]},
725+ {
726+ 'role' : 'assistant' ,
727+ 'parts' : [
728+ {
729+ 'type' : 'tool_call' ,
730+ 'id' : IsStr (),
731+ 'name' : 'final_result' ,
732+ }
733+ ],
734+ },
735+ {
736+ 'role' : 'user' ,
737+ 'parts' : [
738+ {
739+ 'type' : 'tool_call_response' ,
740+ 'id' : IsStr (),
741+ 'name' : 'final_result' ,
742+ }
743+ ],
744+ },
745+ ]
746+ )
747+ ),
748+ 'logfire.json_schema' : IsJson (
749+ snapshot (
750+ {
751+ 'type' : 'object' ,
752+ 'properties' : {
753+ 'pydantic_ai.all_messages' : {'type' : 'array' },
754+ 'final_result' : {'type' : 'object' },
755+ },
756+ }
757+ )
758+ ),
759+ }
760+ )
761+ chat_span_attributes = summary .attributes [1 ]
762+ assert chat_span_attributes == snapshot (
763+ {
764+ 'gen_ai.operation.name' : 'chat' ,
765+ 'gen_ai.system' : 'test' ,
766+ 'gen_ai.request.model' : 'test' ,
767+ 'model_request_parameters' : IsJson (
768+ snapshot (
769+ {
770+ 'function_tools' : [],
771+ 'builtin_tools' : [],
772+ 'output_mode' : 'tool' ,
773+ 'output_object' : None ,
774+ 'output_tools' : [
775+ {
776+ 'name' : 'final_result' ,
777+ 'parameters_json_schema' : {
778+ 'properties' : {'content' : {'type' : 'string' }},
779+ 'required' : ['content' ],
780+ 'title' : 'MyOutput' ,
781+ 'type' : 'object' ,
782+ },
783+ 'description' : 'The final response which ends this conversation' ,
784+ 'outer_typed_dict_key' : None ,
785+ 'strict' : None ,
786+ 'kind' : 'output' ,
787+ }
788+ ],
789+ 'allow_text_output' : False ,
790+ }
791+ )
792+ ),
793+ 'logfire.span_type' : 'span' ,
794+ 'logfire.msg' : 'chat test' ,
795+ 'gen_ai.input.messages' : IsJson (snapshot ([{'role' : 'user' , 'parts' : [{'type' : 'text' }]}])),
796+ 'gen_ai.output.messages' : IsJson (
797+ snapshot (
798+ [
799+ {
800+ 'role' : 'assistant' ,
801+ 'parts' : [
802+ {
803+ 'type' : 'tool_call' ,
804+ 'id' : IsStr (),
805+ 'name' : 'final_result' ,
806+ }
807+ ],
808+ }
809+ ]
810+ )
811+ ),
812+ 'logfire.json_schema' : IsJson (
813+ snapshot (
814+ {
815+ 'type' : 'object' ,
816+ 'properties' : {
817+ 'gen_ai.input.messages' : {'type' : 'array' },
818+ 'gen_ai.output.messages' : {'type' : 'array' },
819+ 'model_request_parameters' : {'type' : 'object' },
820+ },
821+ }
822+ )
823+ ),
824+ 'gen_ai.usage.input_tokens' : 51 ,
825+ 'gen_ai.usage.output_tokens' : 5 ,
826+ 'gen_ai.response.model' : 'test' ,
827+ }
828+ )
829+
830+
695831def test_instrument_all ():
696832 model = TestModel ()
697833 agent = Agent ()
0 commit comments